Omzy Posted January 13, 2010 Share Posted January 13, 2010 I have a string variable, which for example can have the following values: $string="This is a normal description" $string="This is another description [advanced]" Basically I want to echo $string but if it finds a "[" (square bracket) character in the string it will not echo that part. The square braket, if there is one, will only appear at the end of the string. Link to comment https://forums.phpfreaks.com/topic/188327-string-trim-on-character-occurrence/ Share on other sites More sharing options...
salathe Posted January 13, 2010 Share Posted January 13, 2010 Very similar questions seem to pop up here very regularly. If you're using PHP 5.3 then you can use strstr with its handy 3rd parameter, or you could use any number of other string-functions such as strtok. Link to comment https://forums.phpfreaks.com/topic/188327-string-trim-on-character-occurrence/#findComment-994192 Share on other sites More sharing options...
Omzy Posted January 13, 2010 Author Share Posted January 13, 2010 Hi salathe. I was initially going to use strstr() but then I realised it only works with PHP 5.3. I've just tried strtok() and that seems to do the job. Thanks. Link to comment https://forums.phpfreaks.com/topic/188327-string-trim-on-character-occurrence/#findComment-994202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.