note 37229 deleted from function.substr by didou

From: Date: Fri, 07 Nov 2003 08:38:27 +0000
Subject: note 37229 deleted from function.substr by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-60056@lists.php.net to get a copy of this message
Note Submitter: wels@advanets.com ---- <?php #CORRECTION FOR THE PREVIOUS EXAMPLE #to get a substring between two known strings, to menepulate it ( split it into two parts) #for example: I have this string that have a city and a state, and I need to get the state and the city seperatly $myContent ="hey you , I live in Detroit Michigan, USA and I like it baby"; # not I am adding the space after "live in" because after I get my substring I will split it based on the space between the words $myStartSub = "live in "; $myEndSub =", USA"; $my_substr= substr($myContent,strpos($myContent,$myStartSub )+strlen($myStartSub), strpos($myContent,$myEndSub)); $my_substr= substr($my_substr,0, strpos($my_substr,$myEndSub)); echo " the substring : ".$my_substr; # the end result would be # myEndSub = "Detroit Michigan" #now after we got the string that have the city and state, we can start choping it to two variables $firstSection = substr($my_substr,0, strpos($my_substr," ")); echo "<br> the City :".$firstSection; $SecoundSection= substr($my_substr,strpos($my_substr," " )+strlen(" ")); echo "<br> the state :".$SecoundSection; #the resutl would be like this : //---------->the substring : Detroit Michigan //---------->the City :Detroit //---------->the state :Michigan # ofcourse the last part ( splitting of the string could be done in many other ways, but hey if you know it will only be city and state, then that would work ofcourse unless the sity is san fransisco, or the state is new orliens ?>

« previous php.notes (#60056) next »