RE: [PHP] Can I do this in a single match/replace?

2012-06-28 Thread Ford, Mike
> -Original Message-
> From: Paul Halliday [mailto:paul.halli...@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 " href=http://";
> . $matches[n] . ">" . $matches[n] . ""
> 
> 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, 'http://$1";>$1' , 
$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.f...@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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Can I do this in a single match/replace?

2012-06-27 Thread Chris Testroet

On 6/27/2012 6:26 PM, Paul Halliday wrote:

I have lines that look like (I added intentional line breaks):

alert tcp $HOME_NET 1 -> $EXTERNAL_NET any (msg:"ET EXPLOIT NDMP
Notify Connect - Possible Backup Exec Remote Agent Recon";
flow:established,from_server; content:"|00 00 05 02|"; offset:16;
depth:20; content: "|00 00 00 03|"; offset: 28;
depth: 32; 
reference:url,www.ndmp.org/download/sdk_v4/draft-skardal-ndmp4-04.txt;
reference:url,doc.emergingthreats.net/bin/view/Main/2002068;
classtype:attempted-recon; sid:2002068; rev:8;)

So within this there are reference urls that I would like to turn into
links so that when they are rendered they can be clicked on.

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 "http://";
. $matches[n] . ">" . $matches[n] . ""

Can this be done or do I need to say loop through matches (there can
be none or many) and do a str_replace.

Thoughts? Other ideas?

Thanks.



Look into preg_replace, with the "e" modifier. It allows you to run php 
code for every replace.


Chris


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php