dadamssg Posted June 27, 2009 Share Posted June 27, 2009 I have no idea how to write the function i need. But i want the function to replace all '&'s with "and" within a string. does anyone know how to do this? Link to comment https://forums.phpfreaks.com/topic/163926-solved-pre_replace-help/ Share on other sites More sharing options...
.josh Posted June 27, 2009 Share Posted June 27, 2009 $string = preg_replace('~&~','and',$string); Link to comment https://forums.phpfreaks.com/topic/163926-solved-pre_replace-help/#findComment-864838 Share on other sites More sharing options...
thebadbad Posted June 27, 2009 Share Posted June 27, 2009 I'm sure you know this CV, but for the sake of the OP; when replacing simple strings, str_replace() is more efficient. $str = str_replace('&', 'and', $str); Link to comment https://forums.phpfreaks.com/topic/163926-solved-pre_replace-help/#findComment-864840 Share on other sites More sharing options...
.josh Posted June 27, 2009 Share Posted June 27, 2009 Ah yeah, for some reason it just slipped my mind. Link to comment https://forums.phpfreaks.com/topic/163926-solved-pre_replace-help/#findComment-864842 Share on other sites More sharing options...
dadamssg Posted June 27, 2009 Author Share Posted June 27, 2009 thank you thank you thank you! Link to comment https://forums.phpfreaks.com/topic/163926-solved-pre_replace-help/#findComment-864843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.