Vivid Lust Posted January 11, 2010 Share Posted January 11, 2010 I would like to know how i can trim all of a string after the character # examples: INPUT hello#hello OUTPUT hello and INPUT hi#hi#hi OUTPUT hi Hope that you understand and can help me fast!!! Thanks, Jake Quote Link to comment https://forums.phpfreaks.com/topic/188065-trim-all-of-strong-after/ Share on other sites More sharing options...
Lamez Posted January 11, 2010 Share Posted January 11, 2010 http://us3.php.net/trim Quote Link to comment https://forums.phpfreaks.com/topic/188065-trim-all-of-strong-after/#findComment-992832 Share on other sites More sharing options...
Wolphie Posted January 11, 2010 Share Posted January 11, 2010 Why not just use str_replace to replace all white spaces? (if that's what you're after) Quote Link to comment https://forums.phpfreaks.com/topic/188065-trim-all-of-strong-after/#findComment-992833 Share on other sites More sharing options...
Vivid Lust Posted January 11, 2010 Author Share Posted January 11, 2010 Im looking to get rid of everything after and including the # Could anyone write my the function to do this? thanks Quote Link to comment https://forums.phpfreaks.com/topic/188065-trim-all-of-strong-after/#findComment-992835 Share on other sites More sharing options...
Wolphie Posted January 11, 2010 Share Posted January 11, 2010 I think the shortest and easiest way to do this would be to strip white spaces from the string completely, if that's what you're trying to achieve. <?php $str = "hello# myname is#meh"; $str = str_replace(" ", "", $str); ?> Quote Link to comment https://forums.phpfreaks.com/topic/188065-trim-all-of-strong-after/#findComment-992836 Share on other sites More sharing options...
salathe Posted January 11, 2010 Share Posted January 11, 2010 $input = 'hello#hello'; $hello = strstr($input, '#', TRUE); // PHP 5.3+ $hello = strtok($input, '#'); // PHP 3+ Quote Link to comment https://forums.phpfreaks.com/topic/188065-trim-all-of-strong-after/#findComment-993027 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.