# Can anyone convert this Perl match to PHP?

**URL:** https://forum.kirupa.com/t/can-anyone-convert-this-perl-match-to-php/226958
**Category:** programming
**Created:** [May 25, 2007, 11:07am UTC](https://forum.kirupa.com/t/can-anyone-convert-this-perl-match-to-php/226958 "2007-05-25T11:07:19Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Ben\_Smith](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ben_smith/32/1118_2.png) [@Ben\_Smith](https://forum.kirupa.com/u/Ben_Smith)
#### Post date: [May 25, 2007, 11:07am UTC](https://forum.kirupa.com/t/can-anyone-convert-this-perl-match-to-php/226958/1 "2007-05-25T11:07:19Z")

</div>

Hi all,

Just need a bit of help converting this Perl match into PHP preg\_replace’s.

```auto

$printable_name =~ s/(\w+)/\u\L$1/g;
$printable_name =~ s/\b(And|Of|The|S)\b/\l$1/g;
$printable_name =~ s/'/\\'/;

```

At the moment, I’ve got:

```php

$name = preg_replace("/(\w+)/", "\u\L$1/g", $name);
$name = preg_replace("/\b(And|Of|The|S)\b/","\l$1/g", $name);
$name = preg_replace("/'/", "\\'/", $name, 1);

```

But my regular expressions are rusty, let alone working from Perl to PHP.  
Cheers in advance,

Ben
