Reputation: 326
I have the following PHP string
$string = "Hello World<br>- 8/7/2013<br>Hello World";
So basically, I need to get the information between a dash and space (-
) and the closest line break tag. Your help is very much appreciated! I looked for hours but haven't been successful. I don't think that preg_replace
would help either.
Upvotes: 0
Views: 72
Reputation: 6230
Try this
function getData($haystack) {
$dash = strpos($haystack, "- ") + 2;
$br = strpos($haystack, "<br>", $dash);
return substr($haystack, $dash, $br - $dash);
}
Upvotes: 0
Reputation: 2202
You can use preg_match
:
if(preg_match("~-\s(.*?)<br>~", $string, $matches)) {
$data = $matches[1];
}
Upvotes: 1