Perad Posted February 4, 2008 Share Posted February 4, 2008 $this->str = preg_replace('watch?v=', 'v/', $this->str); I want to replace any instance of 'watch?v=' with 'v/'. I have tinkered with various slashes but I cannot get this to work. Can someone help me get this working please. Quote Link to comment https://forums.phpfreaks.com/topic/89346-preg_replace/ Share on other sites More sharing options...
thebadbad Posted February 4, 2008 Share Posted February 4, 2008 You need delimiters for the pattern, and you need to escape the question mark: <?php $this->str = preg_replace('|watch\?v=|', 'v/', $this->str); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89346-preg_replace/#findComment-457508 Share on other sites More sharing options...
thebadbad Posted February 4, 2008 Share Posted February 4, 2008 Come to think of it, you really should use str_replace instead, as long as it's this simple Quote Link to comment https://forums.phpfreaks.com/topic/89346-preg_replace/#findComment-457517 Share on other sites More sharing options...
Aureole Posted February 4, 2008 Share Posted February 4, 2008 You should use str_replace(), it's a lot faster. Quote Link to comment https://forums.phpfreaks.com/topic/89346-preg_replace/#findComment-457519 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.