[Phpwm] mysql search / replace

Keith Pope Keith.Pope at allpay.net
Mon Oct 8 14:31:23 BST 2007


I think mysql regex function is only for comparison so you cant use it as a select modifier.

You could use preg to clean the data as it comes out of the db like:

$result = preg_replace('/\\s{2,}/', '', $subject);

You may be able to do it at the mysql server using a procedure or routine. Have a look on the mysql forge there may be some ready made.  


Keith Pope
Web Developer

-----Original Message-----
From: Phil Beynon [mailto:phil at infolinkelectronics.co.uk] 
Sent: 08 October 2007 12:44
To: West Midlands PHP User Group
Subject: RE: [Phpwm] mysql search / replace

> Have you tried:
>
> TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr 
> FROM] str)
>
> Returns the string str with all remstr prefixes or suffixes removed. 
> If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is 
> assumed. remstr is optional and, if not specified, spaces are removed.
>
> mysql> SELECT TRIM('  bar   ');
>         -> 'bar'
> mysql> SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx');
>         -> 'barxxx'
> mysql> SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx');
>         -> 'bar'
> mysql> SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz');
>         -> 'barx'
> This function is multi-byte safe.
>
>
> Keith Pope
> Web Developer
>

Hi Keith,
No that won't work as its within the text and I don't want to remove all spaces as such, just multiples of three.

The bit of text in the field looks like;

<div id="toplinks" align="left">
<a class="menubutton"
href="javascript:history.go(-1)">BACK&nbsp;&nbsp;&nbsp;   </a>
</div>

and it should look like;

<div id="toplinks" align="left">
<a class="menubutton"
href="javascript:history.go(-1)">BACK&nbsp;&nbsp;&nbsp;</a>
</div>

I know whay it happened - its one of these htmlentities going into a textbox then getting re-encoded screwups.
What I can't seem to get though is a direct pattern match on three normal spaces (as opposed to non breaking spaces), hence teh question as to if there was a single char wildcard as against a '%' nlength wildcard.

P

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.4/1056 - Release Date: 07/10/2007
18:12


--

allpay.net Limited, Fortis et Fides, Whitestone Business Park, Whitestone, Hereford, HR1 3SE. 

Registered in England No. 02933191. UK VAT Reg. No. 666 9148 88. 



Telephone: 0870 243 3434, Fax: 0870 243 6041. 

Website: www.allpay.net

Email: enquiries at allpay.net 



This email, and any files transmitted with it, is confidential and intended solely for the use of the individual or entity to whom it is addressed. If you have received this email in error please notify the allpay.net Information Security Manager at the number above.



More information about the Phpwm mailing list