Jump to content

replace wildcards in string


violinrocker

Recommended Posts

the format of the initial link is

 

http://bs.something.com/gghs-hc/09889/1442/importantparthere      i want it to look like

http://something.com/v/importantparthere

 

i want to remove gghs-hc/09889/1442 (which are dynamic)

 

i tried...

$link = preg_replace( "http://bs.something.com/([^/\.]+)/([^/\.]+)/([^/\.]+)/", "http://www.something.com/v/", $link);

 

but its having an error

Link to comment
https://forums.phpfreaks.com/topic/227766-replace-wildcards-in-string/
Share on other sites

add delimiter to your regex pattern

<?php
$link = 'http://bs.something.com/gghs-hc/09889/1442/importantparthere      i want it to look like';
$link = preg_replace( "#http://bs.something.com/([^/\.]+)/([^/\.]+)/([^/\.]+)/#", "http://www.something.com/v/", $link);
echo $link;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.