# PHP - preg\_replace

**URL:** <https://forum.kirupa.com/t/php-preg-replace/232268>\
**Category:** programming\
**Created:** [July 12, 2007, 8:03am UTC](https://forum.kirupa.com/t/php-preg-replace/232268 "2007-07-12T08:03:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sceneshift](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sceneshift](https://forum.kirupa.com/u/sceneshift)\
**Post date:** [July 12, 2007, 8:03am UTC](https://forum.kirupa.com/t/php-preg-replace/232268/1 "2007-07-12T08:03:40Z")

</div>

Hi Forums,

Ok, so I have a string made up of html like so:

```auto

<div style="blahblah">%1</div><div>%2</div>

```

And I am using php to strip the tags, explode the string in order to leave just %1 and %2. Now I am using preg\_replace to reconstruct the data before the tags were stripped but replace the %1 and %2 with html data pulled from a database. This all works fine.

The problem I have is that when the %n (where n is a number) exceeds single digits, the regular expression I am using will only look at the first digit. Here is my regex:

```php
"/%['. $this_item .']/"

```

Where $this\_item can be any number from 0-infinity (or in this case, 100000 😉 ) and corresponds to an ID number from a database.

Any help would be appreciated, perhaps using a different technique would suffice?

Cheers!
