Jump to content


Photo

Reg ex


  • Please log in to reply
3 replies to this topic

#1 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 01 June 2006 - 01:55 AM

Each time I think I get these something happens which indicates i dont.

OK I have a html file that a place contents into a string using file_get
_contents.

now I want to return from the string everything from '<center><br>' upto and including '</textarea>' which have tags inbetween and newlines etc. etc.

Now I have tried

preg_match('/<center><br>.\s*<\/textarea>/', $string, $outstr);

preg_match('/<center><br>(?!<\/textarea>).\s*<\/textarea>/', $string, $outstr);

and some other embarrassing combinations.

Bit of help would be very much appreciated.

follow me on twitter @PHPsycho

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 01 June 2006 - 04:14 AM

try this:
preg_match("/<center><br>.*?<\/textarea>/",$string, $outstr);

$outstr[0] will contains everything between but not included '<center><br>' and '</textarea>'

pregmatch is non greedy and it will stop at the first </textarea>.
Also, you need to use double quote to specify the pattern string. PHP will not parse escape char with single quote.

Tom
Life's too short for arguing.

#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 01 June 2006 - 10:22 AM

Thanks for reply but unfortunately no joy there - output array is empty.

Any other suggestions?
follow me on twitter @PHPsycho

#4 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 01 June 2006 - 10:34 AM

Try this...

preg_match("`<center><br>(.*)</textarea>`",$string,$outstr);
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users