Hi,
is there any good way to remove everything from a string except the content inside a <span>
tag?
Example:
$myString = "mso:dkdlfkdl */1134*/** <span>Hello</span>";
i want:
$myNewString = '<span>Hello</span>';
??
Hi,
is there any good way to remove everything from a string except the content inside a <span>
tag?
Example:
$myString = "mso:dkdlfkdl */1134*/** <span>Hello</span>";
i want:
$myNewString = '<span>Hello</span>';
??
Think of it the other way around: you want to get only the span tags and discard everything else. That can be done easily using regular expressions and then imploding the results back into one string:
$myString = "mso:dkdlfkdl */1134*/** <span>Hello</span>";
// Find all span elements and put them in $matches
preg_match_all("~(<span>.*?</span>)~", $myString, $matches);
// Combine all spans into one string
$myNewString = implode('', $matches[0]);