PDA

View Full Version : Quick and easy ereg question


heath
10-28-1999, 06:07 PM
Should be easy for the wizards here:<?
## Attempting to grab/extract text between &quot;<open>&quot; and &quot;<close>&quot; below


$str = &quot;a bunch of irrelevant stuff text here
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]<open>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]Start grabbing text here
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]More misc stuff here
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]<close>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]lots of stuff to ignore here&quot;;
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]

## my reg. expressions are very week, but here's a variation of what
## I've been trying:
$new = ereg (^<open>+<close>, $str);

?>

Justin
10-28-1999, 06:40 PM
$str = ereg (&quot;<open>(.+)<close>&quot;, &quot;\\1&quot;, $str);

Quick 'N' Easy ;)

[This message has been edited by Justin (edited 10-28-99)]

heath
10-30-1999, 08:02 PM
Justin - thanks for the help.

Here's what I had to end up using:


$str=&quot;jgflkgfjlkds <start> goodies <done>jgfdlksa&quot;;
$regex =[nbsp][nbsp]&quot;<start>(.*)<done>&quot;;
[nbsp]if (ereg($regex, $str, $matched)) {
print $matched[1]; }

which worked perfect.


In your example code - what does the &quot;//1&quot; do??

Thanks again for the help.

Heath