MikeDXUNL Posted June 4, 2008 Share Posted June 4, 2008 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 Link to comment https://forums.phpfreaks.com/topic/108624-finding-text-within-text-then-creating-array/ Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 You want all occurences of hihihi with a number next to it? =P eregi('hihihi([0-9]*)', $text, $matches); Link to comment https://forums.phpfreaks.com/topic/108624-finding-text-within-text-then-creating-array/#findComment-557114 Share on other sites More sharing options...
MikeDXUNL Posted June 4, 2008 Author Share Posted June 4, 2008 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 Link to comment https://forums.phpfreaks.com/topic/108624-finding-text-within-text-then-creating-array/#findComment-557117 Share on other sites More sharing options...
effigy Posted June 4, 2008 Share Posted June 4, 2008 <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> Link to comment https://forums.phpfreaks.com/topic/108624-finding-text-within-text-then-creating-array/#findComment-557420 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.