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? Quote 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. Quote 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 Quote 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); Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.