Re: Regular expression question
| From: | Robin Vickery | Date: | Thu, 11 Aug 2005 14:40:31 +0000 |
| Subject: | Re: Regular expression question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-220434@lists.php.net to get a copy of this message | ||
On 8/11/05, Leon Vismer <lvismer@tasmer.co.za> wrote:
> Hi
>
> I would like to convert from one naming convention within a sql statement to
> another.
>
> I have the following,
>
> <code>
> $str = "insert into userComment (userID, userName, userSurname) values (0,
> 'Leon', 'Vismer')";
>
> $match = array(
> "/([a-z]+)(ID)/",
> "/([a-z]+)([A-Z])/"
> );
>
> $replace = array(
> "\$1_id",
> "\$1_\$2"
> );
<?php
$str = "insert into userComment (userID, userName, userSurname) values
(0, 'Leon', 'Vismer')";
$match = '/(?<=[a-z])([A-Z]+)/e';
$replace = 'strtolower("_$1")';
print preg_replace($match, $replace, $str);
?>
insert into user_comment (user_id, user_name, user_surname) values (0,
'Leon', 'Vismer')
-robin