How would I go about extracting everything between some specifie characters? If I have something like
$myname = 'My name is \'Brian\';';
How would I go about extracting the name between the single quotes?
Here's one way:
if ((($pos_1 = strpos($myname, "'") + 1) !== false) && (($pos_2 = strpos($myname, "'", $pos_1)) !== false)) { echo substr($myname, $pos_1, $pos_2 - $pos_1); }
Heres another way.
<?php $myname = 'My name is \'Brian\';'; $parts = explode("'",$myname); echo $parts[0]." "; /* My name is */ echo $parts[1]; /* Brian */ /* echo out $parts[2] will output just the ; */ ?>