Removing redundant entries in RegExp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Removing redundant entries in RegExp

Post by anjanesh »

Again another RegExp q:
I managed to do a pattern /..../is that will be give me the results. But there are some which are repeated - because they exist in the string to search for.
What do I have to do to get unique ones.
For example, a string may contain a lot of links in the form
<a id="12345" href="something">link</a>

Code: Select all

<a id=&quote;12345&quote; href=&quote;something&quote;>link</a>
<a id=&quote;54321&quote; href=&quote;something&quote;>link</a>
<a id=&quote;99999&quote; href=&quote;something&quote;>link</a>
<a id=&quote;12345&quote; href=&quote;something&quote;>link</a>
<a id=&quote;85858&quote; href=&quote;something&quote;>link</a>
My pattern matches 5 - there are 2 that are same. How do I remove redundant entries ? The result should be 4 matches.
Im using preg_match_all.
Thanks
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

try array_unique on matches array.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Thats after preg_match_all has been executed - any way to have it done while searching in RegExp ?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

The RegExp wont do that unfortunately.... I'd go with n00b Saibot's option :D
Post Reply