2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by langsor
0

Hi

Regular expressions are tricky and can be very picky. If you have different input structures than the ones you provided, I cannot guarantee it to work with those other structures.

Hope it helps

<?php
// TEST SUBJECT STRINGS
$link1 = 'http://test.site.com/cat1/cat2/123.html';
$link2 = 'http://test.site.com/cat1/cat2/cat3/1.html';

// find this pattern
$pattern = '#^(.*/)(\d+)(\.html)$#';
// make these replacements
$replace = '\\1page-\\2.txt';

// regular expression preg_replace ...
print preg_replace( $pattern, $replace, $link1 );
print "\n<br>\n";
print preg_replace( $pattern, $replace, $link2 );

/** OUTPUT OF ABOVE TESTS
http://test.site.com/cat1/cat2/page-123.txt http://test.site.com/cat1/cat2/cat3/page-1.txt
**/
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.