[Phpwm] mysql search / replace

Keith Pope Keith.Pope at allpay.net
Mon Oct 8 12:05:54 BST 2007


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

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

> Phil Beynon wrote:
> > Using;
> >
> > UPDATE tablename SET fieldname = REPLACE(fieldname, 'existing 
> > text','replacement text')
> >
> > is there a way of setting a single char wildcard in 'existing text'?
>
>
> Does MySQL support regular expressions? (Presumably yes...)
>
>
> - --
> David Goodwin

Must admit I hadn't tried to use a REGEX specifically in there.

The problem I was getting was a field had got three spaces in it which were causing something to pad across from where it should have been, this had happened in a few places - but I couldnt make it match and replace multiple spaces which seemed odd.

Phil
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