For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > May 2004 > string function









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author string function
Dewey

2004-05-20, 9:30 pm

is there a string function for PHP 4 that will let me get the text between a
certain string? ex: <string>this text i want</string> .

-dewey


Patrick Crocker

2004-05-20, 10:30 pm

You can use regular expressions:
<?
$string = "<string>this text i want </string>";
if (preg_match('/<.*?>(.*?)<.*?>/', $string, $match)) {
echo "<pre>";
print_r($match);
echo "</pre>";
}
?>
or...
<?
$string = "<string>this text i want </string>";
$string .= "<another_string>more text that I want</another_string>";
if (preg_match_all('/<.*?>(.*?)<.*?>/', $string, $match)) {
echo "<pre>";
print_r($match);
echo "</pre>";
}
?>

- Patrick.



"Dewey" <annoyinglittlekid@hotmail.com> wrote in message
news:8Ebrc.28$T82.2127@eagle.america.net...
> is there a string function for PHP 4 that will let me get the text between

a
> certain string? ex: <string>this text i want</string> .
>
> -dewey
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com