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. 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); ?> 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 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. Link to comment https://forums.phpfreaks.com/topic/89346-preg_replace/#findComment-457519 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.