balkan7 Posted June 28, 2012 Share Posted June 28, 2012 Ok i am using this code for replace url link: $html = preg_replace('/gallery\.php\?show=([0-9]+)/i','gallery/$1',$html); with this code show me this result: gallery?show=5 i need this result: gallery/5 Link to comment https://forums.phpfreaks.com/topic/264954-preg_replace-for-url-links/ Share on other sites More sharing options...
xyph Posted June 28, 2012 Share Posted June 28, 2012 Huh? <?php $html = 'gallery.php?show=5'; $html = preg_replace('/gallery\.php\?show=([0-9]+)/i','gallery/$1',$html); echo $html; // outputs gallery/5 ?> Link to comment https://forums.phpfreaks.com/topic/264954-preg_replace-for-url-links/#findComment-1357747 Share on other sites More sharing options...
balkan7 Posted June 28, 2012 Author Share Posted June 28, 2012 Then what's wrong with my site show me gallery?show=5 .htaccess RewriteRule ^gallery/([0-9]+)/?$ gallery.php?show=$1 [QSA,L] Link to comment https://forums.phpfreaks.com/topic/264954-preg_replace-for-url-links/#findComment-1357749 Share on other sites More sharing options...
balkan7 Posted June 28, 2012 Author Share Posted June 28, 2012 If i use this code then show: gallery?show=5 if i remove $html = str_replace('gallery.php','gallery',$html); then show me gallery/5 How can fix it ? $html = str_replace('gallery.php','gallery',$html); $html = preg_replace('/gallery\.php\?show=([0-9]+)/i','gallery/$1',$html); Link to comment https://forums.phpfreaks.com/topic/264954-preg_replace-for-url-links/#findComment-1357752 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.