violinrocker Posted February 15, 2011 Share Posted February 15, 2011 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 More sharing options...
salathe Posted February 15, 2011 Share Posted February 15, 2011 The error should give you a hint. If not, post it here and we can guide you. (The problem is very clear already, but handing folks answers isn't really helping at all!) Link to comment https://forums.phpfreaks.com/topic/227766-replace-wildcards-in-string/#findComment-1174605 Share on other sites More sharing options...
violinrocker Posted February 15, 2011 Author Share Posted February 15, 2011 problem is... it would not accept / as a delimiter and it doesnt want alphanumeric and backslashes... Link to comment https://forums.phpfreaks.com/topic/227766-replace-wildcards-in-string/#findComment-1174711 Share on other sites More sharing options...
Jessica Posted February 15, 2011 Share Posted February 15, 2011 Is it always a .com? If the url is always the same, I'd remove everything after the .com (but I hate regex. ) Link to comment https://forums.phpfreaks.com/topic/227766-replace-wildcards-in-string/#findComment-1174713 Share on other sites More sharing options...
sasa Posted February 16, 2011 Share Posted February 16, 2011 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; ?> Link to comment https://forums.phpfreaks.com/topic/227766-replace-wildcards-in-string/#findComment-1174880 Share on other sites More sharing options...
violinrocker Posted February 16, 2011 Author Share Posted February 16, 2011 ^ thanks this works... was a big help giving out a suggestion instantly =D Link to comment https://forums.phpfreaks.com/topic/227766-replace-wildcards-in-string/#findComment-1174900 Share on other sites More sharing options...
salathe Posted February 16, 2011 Share Posted February 16, 2011 In case you haven't read already, there is a nice section in the PHP manual on using regular expressions. Relevant to the code posted above is the section on delimiters. Link to comment https://forums.phpfreaks.com/topic/227766-replace-wildcards-in-string/#findComment-1174914 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.