mga_ka_php Posted June 19, 2007 Share Posted June 19, 2007 how do you explode string with two conditions, space and newline? i use strtok but i could only use 1 condition i cannot use the 2 condition space and newline i want to explode a string with if a string has a space and newline? how do i do that? thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/56182-explode-string/ Share on other sites More sharing options...
Dragen Posted June 19, 2007 Share Posted June 19, 2007 First convert all newlines to spaces. <?php $string = "I am a random\nstring. Please feed me cheese."; $string = str_replace('\n', ' ', $string); //replaces all new lines with spaces $newstring = explode(' ', $string); print_r($newstring); ?> That should work Quote Link to comment https://forums.phpfreaks.com/topic/56182-explode-string/#findComment-277496 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.