SCook Posted January 3, 2008 Share Posted January 3, 2008 Hi all, I want to parse a string, for example: This is |x| my string. Where |x| needs to change to something else. And there may be more than one instance of this speial character. What would be the best way to go abot it? Link to comment https://forums.phpfreaks.com/topic/84366-parsing-some-sepcial-characters-from-a-string/ Share on other sites More sharing options...
effigy Posted January 3, 2008 Share Posted January 3, 2008 str_replace. Link to comment https://forums.phpfreaks.com/topic/84366-parsing-some-sepcial-characters-from-a-string/#findComment-429720 Share on other sites More sharing options...
SCook Posted January 3, 2008 Author Share Posted January 3, 2008 Yeah, str_replace would work, exept the special characters will be anyting from |s1|...|s11|. Now, I can loop through and do it, but I was just hoping there'd be a better way Link to comment https://forums.phpfreaks.com/topic/84366-parsing-some-sepcial-characters-from-a-string/#findComment-429724 Share on other sites More sharing options...
effigy Posted January 3, 2008 Share Posted January 3, 2008 echo preg_replace('/\|s\d+\|/', 'replacement', $str); Link to comment https://forums.phpfreaks.com/topic/84366-parsing-some-sepcial-characters-from-a-string/#findComment-429729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.