Jump to content

Get A String Between 2 Markers..?


cyfer65

Recommended Posts

Is there any universal PHP function to get the string between 2 specified markers in a string..??<<<$RandomText>>>like say I wanted to always get the $RandomText that was between "<<<" and ">>>" is there any PHP function to do this..??like StringBetween($Var, $Start, $End)

Link to comment
Share on other sites

You could use regular expressions:

preg_match_all("/<<<(.*?)>>>/", $string, $matches);print_r($matches);

Link to comment
Share on other sites

<?phpfunction stringBetween($var, $start, $end) {	return preg_match('{' . preg_quote($start) . '(.*?)' . preg_quote($end) . '}s', $var, $m)		? $m[1]		: '';}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...