Hi there, If I have a sentence, with a URL in (it starts with a url) for example:
http://www.phpbuilder.com/board/newthread.php?s=&action=newthread&forumid=10"Some kind of text here etc etc.
How do I go about selecting all the text up to the " and putting it into a variable therefore getting rid of the latter text?
Thanks in advance,
Chris Evans
Strictly speaking, if you just wanted all the text up to the first ", then [man]substr[/man] and [man]strpos[/man] would suffice.
if(($pos = strpos($string, '"')) !== false) { echo substr($string, 0, ($pos + 1)); }
Alternatively, you could look at explode...
$theurl = 'http://www.phpbuilder.com/board/newthread.php?s=&action=newthread&forumid=10"Someothertext'; $theurl = explode('"', $theurl); echo $theurl[0];
Hi - superb, thanks to both! 🙂