Alternative for my preg_replace code

Posted by Ben Sinclair on Stack Overflow See other posts from Stack Overflow or by Ben Sinclair
Published on 2010-04-01T00:13:13Z Indexed on 2010/04/01 0:23 UTC
Read the original article Hit count: 646

Filed under:
|

Here is my code... basically it finds any page-NUMBER- within a variable and then replaces it with a page url from an array

$content_text = preg_replace("/page-(\d+)-/sie", '$pageurl[$1]', $content_text);

It works a treat until the NUMBER it finds isn't in the array and it returns an error...

Is there another efficient way I could do this instead?

I liked my code above because it was simple but I may have to use more complex code...

© Stack Overflow or respective owner

Related posts about php

Related posts about regex