-
Senior Member
regexs - preg_replace
Hi,
I'm trying to filter out links from a webpage but list them at the bottom with this:
preg_replace('/href="([^"]+)"[^>]*>(.+?)<\/a>/ie','listPossibleLinks("\\1")', $html);
It works for <a href="index">bleh</a> but how would i write it that it would also work for single quotes: <a href='index'>bleh</a>
That's the first part.
For another function I need set a target="_blank" for all links in a given string. Some already have a target, some don't.
I suck at regex, reading all about it but just don't get it. Thanks for any help!
Vincent
SWIS BV
Last edited by Markp.com on 07-23-2003 at 02:25 AM
-
No!
Re: regexs - preg_replace
Originally posted by Vincent26381
Hi,
I'm trying to filter out links from a webpage but list them at the bottom with this:
preg_replace('/href="([^"]+)"[^>]*>(.+?)<\/a>/ie','listPossibleLinks("\\1")', $html);
It works for <a href="index">bleh</a> but how would i write it that it would also work for single quotes: <a href='index'>bleh</a>
not testing this, but try
preg_replace('/href=["']([^"]+)["'][^>]*>(.+?)<\/a>/ie','listPossibleLinks("\\1")', $html);
that's a bracket with a quote and an apostraphe (may need to be escaped since you are using apostraphe's to define the string). hypothetically, it should match href="..." or href="...' or href='..." or href='...'
-
Senior Member
Thanks!
Will try
Vincent
SWIS BV
Last edited by Markp.com on 07-23-2003 at 02:25 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|