return text inbetween...
Moderator: General Moderators
return text inbetween...
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]'
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
Re: return text inbetween...
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\]/is-
dan.kotowski
- Forum Newbie
- Posts: 8
- Joined: Thu Jul 20, 2006 10:22 pm
I have a dictionary file that has entries like this:How would I get just the part after the sortkey, so that they would end up like this:???
Code: 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";-
dan.kotowski
- Forum Newbie
- Posts: 8
- Joined: Thu Jul 20, 2006 10:22 pm
I've got this:But I need it to read a file that contains an entire dictionary. How would I set that up to just give me the sortlist part?
Code: Select all
<?php
$subject = <text from file>;
$pattern = "/sortkey=\"(.*?)\"/i";
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($matches);
?>