rtrim a string with MySQL"s function

rtrim a string with MySQL"s function

am 05.12.2007 08:27:15 von Shelley Shyan

--_000_978687B2351D0E41B3DAB075B5120FC573064B62D0mailmorodoc nc_
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64

SGkgYWxsLA0KDQpJdCdzIHJlYWxseSBmcnVzdHJhdGluZywgSSBnb3QgYSBw cm9ibGVtIHRvIHRy
aW0gYSBzdHJpbmcgdXNpbmcgTXlTUUwncyBmdW5jdGlvbi4NCg0KVGhlIGZh Y3QgaXMgdGhhdCBJ
IHdhbnQgdG8gcnRyaW0gYSBudW1iZXIgZnJvbSBhIHN0cmluZywgdGhhdCBp czoNCmlmIHRoZSBz
dHJpbmcgaXMgICBhYmMyMzIxNDEzNDEyLCBJIHdhbnQgdGhlIGZ1bmN0aW9u IHRvIHJldHVybiAy
MzIxNDEzNDEyOw0KICAgICAgICAgICAgICAgICAgICAgIGMxMjMsICAgICAg ICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMTIzOw0K ICAgICAgICAgICAg
ICAgICAgICAgIDQ1Njc4OSwgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAg
ICAgICAgICAgICAgICA0NTY3ODk7DQoNCklzIHRoZXJlIGEgZmFzdGVyIHdh eSB0byBtYW5hZ2Ug
dGhhdD8NCg0KVGhlIGZhc3RlciwgdGhlIGJldHRlci4gOikNCg0KVGhhbmsg eW91IGZvciB5b3Vy
IGNvbnNpZGVyYXRpb24gYW5kIHdhaXRpbmcgZm9yIHlvdXIgYW5zd2VyLiA6 KQ0KDQpSZWdhcmRz
LA0KU2hlbGxleQ0KDQo=


--_000_978687B2351D0E41B3DAB075B5120FC573064B62D0mailmorodoc nc_
Content-Type: text/plain; charset=us-ascii

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

Re: rtrim a string with MySQL"s function

am 05.12.2007 10:55:45 von Evert Lammerts

You can use regular expressions in mysql to check for the right format,
but (as far as i know) you can not return any matches: SELECT * FROM
table WHERE column REGEX '[0-9]+';, which returns all records where
column has a digit in its value.

In PHP however, you can easily get the matches:
$var = preg_match('/(\d+)/', $string, $matches);
You can find the first occurring digits of your string in $matches[1].

If your $string is of this form: string = [0-9]*[a-zA-Z]*|string, so
digits and alpha characters are mixed, I guess you'll need to do
something like implode $matches[1..n] if you're using the regex above.

Shelley Shyan wrote:
> Hi all,
>
> It's really frustrating, I got a problem to trim a string using MySQL's function.
>
> The fact is that I want to rtrim a number from a string, that is:
> if the string is abc2321413412, I want the function to return 2321413412;
> c123, 123;
> 456789, 456789;
>
> Is there a faster way to manage that?
>
> The faster, the better. :)
>
> Thank you for your consideration and waiting for your answer. :)
>
> Regards,
> Shelley
>
>

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