Jump to content

Finding Text within Text (then creating array)


MikeDXUNL

Recommended Posts

I was looking through the PHP Manual and got pretty far through it, but can't seem to find a way to find each occurance of a string of text.

 

Such as:

 

<div name="thisclass">hihihi</div>
more text
Lipsum blah blah
etc, ext, lol
<div name="thisclass">hihihi2</div>
even more text etx

 

I want something like

 

Array[0] = hihihi

Array[1] = hihihi2

 

I will probably be able to figure out the array part if somone is kind enough to provide at least the function name, (even so I can read up on it).

 

 

Thanks in Advance,

Mike

 

 

well it isn't necessarily "hihihi[0-9]"

 

here is a better Example:

 

<div name="thisclass">Convert This Text</div>
more text
Lipsum blah blah
etc, ext, lol
<div name="thisclass">You are Feeling Fine today</div>
even more text etx

 

 

Array[0]=Convert This Text

Array[1]=You are Feeling Fine today

 

 

<pre>
<?php
$data = <<<DATA
<div name="thisclass">Convert This Text</div>
more text
Lipsum blah blah
etc, ext, lol
<div name="thisclass">You are Feeling Fine today</div>
even more text etx
DATA;
preg_match_all('%<div name="thisclass">(.+?)</div>%s', $data, $matches);
print_r($matches);
?>
</pre>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.