RE: [PHP] Can I do this in a single match/replace?
| From: | Ford, Mike | Date: | Thu, 28 Jun 2012 11:25:00 +0000 |
| Subject: | RE: [PHP] Can I do this in a single match/replace? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318324@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Paul Halliday [mailto:paul.halliday@gmail.com]
> Sent: 28 June 2012 02:27
> Using preg_match and this pattern I can get the refs:
>
> $pattern = '\reference:url,([^;]+;)\';
>
> which gives me:
>
> $matches[0] = www.ndmp.org/download/sdk_v4/draft-skardal-ndmp4-
> 04.txt
> $matches[1] = doc.emergingthreats.net/bin/view/Main/2002068
>
> now what I would like to do is replace inline adding "<a
> href=http://"
> . $matches[n] . ">" . $matches[n] . "</a>"
>
> Can this be done or do I need to say loop through matches (there can
> be none or many) and do a str_replace.
$new_string = preg_replace($pattern, '<a href="http://$1">$1</a>' , $string);
should do it -- don't *think* you need any pesky \ escapes in the
replacement, but could be wrong on that one, so please suck it and
see...
Cheers!
Mike
--
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS, LS1 3HE, United Kingdom
E: m.ford@leedsmet.ac.uk T: +44 113 812 4730
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm