etrader Posted February 2, 2011 Share Posted February 2, 2011 I have phrases in a string with the structure of "Note: some description" I want to replace "Note with (, but how can I replace the second " with )? Link to comment https://forums.phpfreaks.com/topic/226494-replacing-a-phrase-containing-a-variable/ Share on other sites More sharing options...
BlueSkyIS Posted February 2, 2011 Share Posted February 2, 2011 use str_replace twice? $string = '"Note: some description"'; $string = str_replace('"Note: ','(', $string); $string = str_replace('"',')', $string); echo "string: $string"; Link to comment https://forums.phpfreaks.com/topic/226494-replacing-a-phrase-containing-a-variable/#findComment-1169044 Share on other sites More sharing options...
etrader Posted February 3, 2011 Author Share Posted February 3, 2011 Thanks for your suggestion, but this phrase is within a long string; the string is not limited to this phrase. I need a replacing method to look for "Note: ..... " Link to comment https://forums.phpfreaks.com/topic/226494-replacing-a-phrase-containing-a-variable/#findComment-1169275 Share on other sites More sharing options...
BlueSkyIS Posted February 3, 2011 Share Posted February 3, 2011 same thing. neither the length of the string or other content in the string matter. <?php $string = 'AS FASDGASPING asdg aosgiha sgasgoiasrog rag 09u0er70 asr gas "Note: some description" asdga0idsajg0 s0gasrgho aisg'; $string = str_replace('"Note: ','(', $string); $string = str_replace('"',')', $string); echo "string: $string"; ?> output: string: AS FASDGASPING asdg aosgiha sgasgoiasrog rag 09u0er70 asr gas (some description) asdga0idsajg0 s0gasrgho aisg Link to comment https://forums.phpfreaks.com/topic/226494-replacing-a-phrase-containing-a-variable/#findComment-1169392 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.