Re: get some part of text

From: Date: Fri, 14 Nov 2003 22:16:04 +0000
Subject: Re: get some part of text
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-169694@lists.php.net to get a copy of this message
Well, still no problem. If there are only one instance of the "job_resp errorCode" you just alter the explode() abit. Else, the clever part with array_push() Let me do some online coding here, might contain some errors though, :) $error = new array(); $yourstring = 'job_resp errorCode="4194337" description="Originator you"'; $temp = explode('errorCode="',$yourstring); $count = count($temp); if($temp>1){ for ($i = 0; $i < $count; $i++) { // Loop through the errors / exploded ones step 1/2 $temp2=explode('"',$temp[$i]); array_push($error,$temp2[0]); // Push all the errors variables into an array step 2/2 } for ($i = 0; $i < count($error); $i++) { // Print out all the errors echo $error[0]; } } else { $temp2=explode('"',$temp[0]); echo $temp2[0]; } - - - - The above example I use alot, I find pushing things into array beeing a very handy way of doing things, as its very nice and handles n occurencies. -- Kim Steinhaug --------------------------------------------------------------- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --------------------------------------------------------------- "Qt" <web_tur@yahoo.com> wrote in message news:20031114220128.26598.qmail@pb1.pair.com... > dear Kim, > > Thanks for your clever soltion but; > > If string will have another errorCode before 'job_resp errorCode=" > It will use first one value. > > What can we do better than this one? > > > "Kim Steinhaug" <kim@steinhaug.com> wrote in message > news:20031114213855.85693.qmail@pb1.pair.com... > > You could ofcourse to the "easyway out" splitting, hehe. > > > > example : > > $yourstring = 'job_resp errorCode="4194337" description="Originator you"'; > > $temp = explode('errorCode="',$yourstring); > > $temp2=explode('"',$temp[0]); > > echo $temp2[0]; > > > > Voila! > > > > Should always work, aslong as there there are always " around the text. > > > > -- > > Kim Steinhaug > > --------------------------------------------------------------- > > There are 10 types of people when it comes to binary numbers: > > those who understand them, and those who don't. > > --------------------------------------------------------------- > > > > > > "Qt" <web_tur@yahoo.com> wrote in message > > news:20031114200917.29551.qmail@pb1.pair.com... > > > dear Sirs, > > > > > > I have this string; > > > > > > job_resp errorCode="4194337" description="Originator you" > > > > > > I need to take only errorCode value from this string. I am thinking and > > > thinking and can not find how to to. I can split with "=" but allways > > > erroCode place is changing in the string. > > > > > > Any idea > > > > > > Best Regards

« previous php.general (#169694) next »