return text inbetween...
Posted: Wed Jul 19, 2006 2:29 pm
is there a way that when given a string, it will search the string and return only what is in between lets say '[bob]' and '[/bob]'
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Regular expression (Perl) might look something like this:Tsunexus wrote:is there a way that when given a string, it will search the string and return only what is in between lets say '[bob]' and '[/bob]'
Code: Select all
/\[bob\](.*?)\[\/bob\]/isCode: Select all
<o:ent xmlns:o="http://oup.dataformat.com/doc/OUP_DTD_Dictionary.html" sortkey="aalborg"><o:hwGrp><o:hw>Aal<o:hsb/>borg</o:hw><o:pronGrp><o:pr type="US"> |ˈôlˌbôr(g)|</o:pr><o:pr type="US_IPA"> |ˌɑlˈbɔrg|</o:pr><o:pr type="US_IPA"> |ˌɔlˈbɔrg|</o:pr><o:pr type="UK_IPA"> |ˌɔːlbɔːg|</o:pr></o:pronGrp><o:varGrp> (also<o:v> Ål<o:hsb/>borg</o:v>) </o:varGrp></o:hwGrp><o:SB><o:sense> <o:def> an industrial city and port in northern Jutland, Denmark; pop. 155,000. </o:def></o:sense></o:SB></o:ent>Code: Select all
aalborgCode: Select all
$pattern = "/sortkey=\"(.*?)\"/i";Code: Select all
<?php
$subject = <text from file>;
$pattern = "/sortkey=\"(.*?)\"/i";
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($matches);
?>