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 Quote Link to comment 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!) Quote Link to comment 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... Quote Link to comment 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. ) Quote Link to comment 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; ?> Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.