An alternative to the below regex, is to clobber all of text within the 
href= attribute by using:

$text = preg_replace ("/href=\"[^\"]+\"/", 'href="form_url.php"', $text);

The regex will match href=" followed by 1 or more characters which are 
not " and followed by the " character.

I haven't tested the above code so use with caution. ;)

Regards,
Carlos

Mark Rickerby a écrit :
> With a moderate amount of rows such as you have, my recommendation
> would be to run a task/script to loop through and change the rows one
> by one and resave them... I would do the replacement in PHP, rather
> than SQL, and do it once, rather than filter the value each time it is
> requested.
> 
> eg:
> 
> $db->query("select * from table");
> 
> $records= $db->getRecords();
> 
> foreach($records as $record) {
> 
>       $text = $record->text;
> 
>       $text = 
> preg_replace("/\"mailto\:em...@address\.com\?subject=[a-za-z\s0-9]+\"/",
> '"form_url.php"', $text);
> 
>       $record->text = $text;
> 
>       $record->save();
> 
> }
> 
> 
> If you were using raw sql, it would be UPDATE blah etc... instead of
> $record->save(). The idea being to just run the update once, and clean
> up each row one by one. Having an ORM naturally makes this process a
> lot more straightforward.
> 
> 
> Grüße,
> 
> Mark Rickerby
> http://maetl.net/
> -------------------------------------------------------------------------------
> Cell. +642102785644 | Email. [email protected]
> PO Box 4452, Shortland Street, Auckland 1140, NZ
> -------------------------------------------------------------------------------
> 
> 
> 
> 
> On Fri, Jun 19, 2009 at 1:15 PM, David
> Turton<[email protected]> wrote:
>> Hi All,
>>
>> I’m familiar with regular expressions, and I’m familiar with replace sql
>> queries, but I can’t get them working together. Google and mysql.com haven’t
>> been much help.
>>
>>
>>
>> Or other suggestions for doing this are welcome??
>>
>>
>>
>> Need to replace
>>
>>
>>
>> <a href=”mailto:[email protected]?subject=a Subject String”><img
>> src=”img.gif” /></a>
>>
>>
>>
>> With
>>
>>
>>
>> <a href=”form_url.php”><img src=”img.gif” /></a>
>>
>>
>>
>> The variable is the “A Subject String”, all else is common across all
>> records. They are all strings, alphanumeric only e.g. [A-Za-z0-9 ] selects
>> all records.
>>
>> There are 102 records.
>>
>>
>>
>> Thanks for any help.
>>
>> Cheers
>>
>> Dave T

--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---

Reply via email to