[PHP] parsing a string
Hey everyone Having a bit of trouble with something. I have a string which has known patterns. $string"CampusBob (Williams)~\toms more crap)~\blah blah blah)~\"; What I am looking for is Location which is Campus Location Name which is Bob (Williams) Help? - Do you Yahoo!? vote.yahoo.com - Register online to vote today!
Re: [PHP] Parsing a string
check explode() ;) http://www.php.net/manual/en/function.explode.php Regrads, Khalid Al-kary Hi- I'd like to parse the string returned by popen("uptime", "r");. The string that is returned is: 9:47am up 37 days, 16:24, 1 user, load average: 0.09, 0.02, 0.00 What I'd like is 5 strings...the first contains "37 days, 16:24", the second "1 user", the third "0.09", the fourth "0.02", and the fifth "0.00". Any easy way to do this? Thanks very much in advance! -Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Parsing a string
Just use explode() and then dont use what you dont want. Mike *** REPLY SEPARATOR *** On 03/01/2003 at 9:49 AM Greg wrote: >Hi- >I'd like to parse the string returned by popen("uptime", "r");. The string >that is returned is: > >9:47am up 37 days, 16:24, 1 user, load average: 0.09, 0.02, 0.00 > >What I'd like is 5 strings...the first contains "37 days, 16:24", the >second >"1 user", the third "0.09", the fourth "0.02", and the fifth "0.00". > >Any easy way to do this? Thanks very much in advance! >-Greg > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Parsing a string
Hi- I'd like to parse the string returned by popen("uptime", "r");. The string that is returned is: 9:47am up 37 days, 16:24, 1 user, load average: 0.09, 0.02, 0.00 What I'd like is 5 strings...the first contains "37 days, 16:24", the second "1 user", the third "0.09", the fourth "0.02", and the fifth "0.00". Any easy way to do this? Thanks very much in advance! -Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] parsing a string
"Dl Neil" <[EMAIL PROTECTED]> wrote in message 042101c157f6$4cd9fb90$c014100a@jrbrown">news:042101c157f6$4cd9fb90$c014100a@jrbrown... > Two inter-dependent problems: > 1 a means of identifying a cipher within the text > 2 a means of replacing the cipher with HTML code Succinctly stated. >space+bird.gif"this is a bird" This is a possibility, but it requires a bit trickier code to recognize & split it. I was hoping for something easier to identify and parse, so maybe: #bird.gif|some text# That should be easy enough to find & explode() -- John A. Grant * I speak only for myself * (remove 'z' to reply) Radiation Geophysics, Geological Survey of Canada, Ottawa If you followup, please do NOT e-mail me a copy: I will read it here -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] parsing a string
"Mike Eheler" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Beyond that, why not keep it conforming to HTML, and use an tag, > for example: > > This is some text . > > That way if you need to view the page "as-is" in a browser or whatever, > it'd still look fine.. go grab yourself some good free html parser code, > and analyse the options. If processat="server" then do your thing, and > re-write the tag. :) I think I want something more simple. The idea is to let the machine do all of the dirty work, not just in looking up the image size, but also formatting the output. For example, I'm already using functions like: emitlink("http://www.microsoft.com","Microsoft";); so I will have a similar function: emitimg("bird.gif","this is a bird"); that will do all of the stuff, not just some of it. -- John A. Grant * I speak only for myself * (remove 'z' to reply) Radiation Geophysics, Geological Survey of Canada, Ottawa If you followup, please do NOT e-mail me a copy: I will read it here -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] parsing a string
Beyond that, why not keep it conforming to HTML, and use an tag, for example: This is some text . That way if you need to view the page "as-is" in a browser or whatever, it'd still look fine.. go grab yourself some good free html parser code, and analyse the options. If processat="server" then do your thing, and re-write the tag. :) Mike Jason G. wrote: > Why don't you do something like this: > > > > Then search for a regx something like (I am not sure of > the exact syntax). > Then parse the found tag, generate your original tag with the generated tag. > > I hope it gives you some good ideas. > > -Jason Garber > IonZoft.com > > > > > > At 12:11 PM 10/18/2001 -0400, John A. Grant wrote: > >> I'm reading some HTML text from a file and echoing it to >> stdout. The HTML text contains but I would rather >> have the server do the work of looking up the image size. >> I know how to lookup the image size with getimagesize(). >> My problem is in coming up with a good format for embedding >> a reference to the image in the text and then writing the code >> to parse it. >> >> So instead of this: >> here is some text > alt="this is a bird"> and here is more text and another >> image > alt="this is a plane"> and more text >> >> I would like to have something like this: >> here is some text [bird.gif,this is a bird] and here >> is more text and another image [plane.gif, this is a plane] >> and more text >> >> Crossing line boundaries is not an issue - each text string >> is complete. I need to be able to dump out the string until I >> see a reference to an image, then extract the name and alt text, >> handle it (by emitting ) and continue to echo text from >> the string until I encounter another image reference. >> >> My problem is in coming up with a syntax for this and then >> to write the code to extract the information. >> >> In the above example, I'm using the syntax: >> [filename,text] >> >> but it's conceivable that the HTML text might also contain >> [some plain text not related to images] >> >> so I thought about some of these: >> {filename,alt text} - not good, text might contain {plain text] >> @filename, alt text@ >> img(filename,alt text) >> >> Using the same @ delimiter at each end might make it easier >> to use explode() to split the text. But perhaps img(filename,text) >> is more elegant, but it might need more skills than I have in using >> regex to recognize it and extract it. Also I need to figure out how >> to extract and echo the plain text around it. >> >> Any ideas are appreciated. Thanks. >> >> -- >> John A. Grant * I speak only for myself * (remove 'z' to reply) >> Radiation Geophysics, Geological Survey of Canada, Ottawa >> If you followup, please do NOT e-mail me a copy: I will read it here >> >> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] parsing a string
John, Two inter-dependent problems: 1 a means of identifying a cipher within the text 2 a means of replacing the cipher with HTML code 1 there are a limited number of graphics formats (.GIF, .JPG, .PNG, etc) and the number you are prepared to contemplate may be even shorter. Thus it would not be difficult to use the filetype as a means to trigger a RegExp - and thus have no need for a "label mechanism" at all. 2 I'm finding RegExps a bit hairy too. However there are a number of illustrations 'out there', eg in PHP and Perl web site articles, and I'm sure there are some you could borrow/amend - I'm coming up to needing one fairly similar if you want to 'trade'/division of labor. Now I just know you're going to say that so far I've dealt with just the first component of [bird.gif,this is a bird] - and just like every Canuck, you'd be right (or at least that's how the rest of us humor you(s))! First let's restate that cipher as space+bird.gif"this is a bird" where "space+" is at least one character of them immediately prior to the file name. Now you can see that the very same RegExp that recognises/pulls out the graphic filename, should also be able to pull out the alt-text, because that is enclosed within quotes (ie just as the HTML will require it). Because the quotes (could even offer the user/author a choice of single or double!) are paired, and the first is immediately after the filename, you won't have problems with other quoted strings getting caught up/misinterpreted! It takes a warped mind... Warped enough for you? =dn - Original Message - From: "John A. Grant" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: 18 October 2001 17:11 Subject: [PHP] parsing a string > I'm reading some HTML text from a file and echoing it to > stdout. The HTML text contains but I would rather > have the server do the work of looking up the image size. > I know how to lookup the image size with getimagesize(). > My problem is in coming up with a good format for embedding > a reference to the image in the text and then writing the code > to parse it. > > So instead of this: > here is some text alt="this is a bird"> and here is more text and another > image alt="this is a plane"> and more text > > I would like to have something like this: > here is some text [bird.gif,this is a bird] and here > is more text and another image [plane.gif, this is a plane] > and more text > > Crossing line boundaries is not an issue - each text string > is complete. I need to be able to dump out the string until I > see a reference to an image, then extract the name and alt text, > handle it (by emitting ) and continue to echo text from > the string until I encounter another image reference. > > My problem is in coming up with a syntax for this and then > to write the code to extract the information. > > In the above example, I'm using the syntax: > [filename,text] > > but it's conceivable that the HTML text might also contain > [some plain text not related to images] > > so I thought about some of these: > {filename,alt text} - not good, text might contain {plain text] > @filename, alt text@ > img(filename,alt text) > > Using the same @ delimiter at each end might make it easier > to use explode() to split the text. But perhaps img(filename,text) > is more elegant, but it might need more skills than I have in using > regex to recognize it and extract it. Also I need to figure out how > to extract and echo the plain text around it. > > Any ideas are appreciated. Thanks. > > -- > John A. Grant * I speak only for myself * (remove 'z' to reply) > Radiation Geophysics, Geological Survey of Canada, Ottawa > If you followup, please do NOT e-mail me a copy: I will read it here > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] parsing a string
Why don't you do something like this: Then search for a regx something like (I am not sure of the exact syntax). Then parse the found tag, generate your I'm reading some HTML text from a file and echoing it to >stdout. The HTML text contains but I would rather >have the server do the work of looking up the image size. >I know how to lookup the image size with getimagesize(). >My problem is in coming up with a good format for embedding >a reference to the image in the text and then writing the code >to parse it. > >So instead of this: > here is some text alt="this is a bird"> and here is more text and another > image alt="this is a plane"> and more text > >I would like to have something like this: > here is some text [bird.gif,this is a bird] and here > is more text and another image [plane.gif, this is a plane] > and more text > >Crossing line boundaries is not an issue - each text string >is complete. I need to be able to dump out the string until I >see a reference to an image, then extract the name and alt text, >handle it (by emitting ) and continue to echo text from >the string until I encounter another image reference. > >My problem is in coming up with a syntax for this and then >to write the code to extract the information. > >In the above example, I'm using the syntax: > [filename,text] > >but it's conceivable that the HTML text might also contain > [some plain text not related to images] > >so I thought about some of these: > {filename,alt text} - not good, text might contain {plain text] > @filename, alt text@ > img(filename,alt text) > >Using the same @ delimiter at each end might make it easier >to use explode() to split the text. But perhaps img(filename,text) >is more elegant, but it might need more skills than I have in using >regex to recognize it and extract it. Also I need to figure out how >to extract and echo the plain text around it. > >Any ideas are appreciated. Thanks. > >-- >John A. Grant * I speak only for myself * (remove 'z' to reply) >Radiation Geophysics, Geological Survey of Canada, Ottawa >If you followup, please do NOT e-mail me a copy: I will read it here > > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] >To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] parsing a string
I'm reading some HTML text from a file and echoing it to stdout. The HTML text contains but I would rather have the server do the work of looking up the image size. I know how to lookup the image size with getimagesize(). My problem is in coming up with a good format for embedding a reference to the image in the text and then writing the code to parse it. So instead of this: here is some text and here is more text and another image and more text I would like to have something like this: here is some text [bird.gif,this is a bird] and here is more text and another image [plane.gif, this is a plane] and more text Crossing line boundaries is not an issue - each text string is complete. I need to be able to dump out the string until I see a reference to an image, then extract the name and alt text, handle it (by emitting ) and continue to echo text from the string until I encounter another image reference. My problem is in coming up with a syntax for this and then to write the code to extract the information. In the above example, I'm using the syntax: [filename,text] but it's conceivable that the HTML text might also contain [some plain text not related to images] so I thought about some of these: {filename,alt text} - not good, text might contain {plain text] @filename, alt text@ img(filename,alt text) Using the same @ delimiter at each end might make it easier to use explode() to split the text. But perhaps img(filename,text) is more elegant, but it might need more skills than I have in using regex to recognize it and extract it. Also I need to figure out how to extract and echo the plain text around it. Any ideas are appreciated. Thanks. -- John A. Grant * I speak only for myself * (remove 'z' to reply) Radiation Geophysics, Geological Survey of Canada, Ottawa If you followup, please do NOT e-mail me a copy: I will read it here -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Parsing a string
Oh, yeah... my favorite: explode()! $var = '1,2,3,4,5,6,7,8,9,10'; $var_array = explode(',',$var); /* will become: $var_array[0] = '1'; $var_array[1] = '2'; $var_array[2] = '3'; $var_array[3] = '4'; ... and so on */ as you notice the array starts from 0 Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) [EMAIL PROTECTED] www.phpbeginner.com -Original Message- From: Todd Cary [mailto:[EMAIL PROTECTED]] Sent: Friday, February 23, 2001 11:41 PM To: [EMAIL PROTECTED] Subject: [PHP] Parsing a string I have a comma delimited string that I need to parse into an array. Is there a PHP function that will do that ? Many thanks.. Todd -- Todd Cary Ariste Software [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Parsing a string
From: "Todd Cary" <[EMAIL PROTECTED]> > Thanks all!! > > split() works like a champ!! > > Todd > > -- > Todd Cary > Ariste Software > [EMAIL PROTECTED] > If you're just tokenising by a comma, don't use split(), use explode(). split() accepts a regular expression for the separator, whereas explode() accepts just a normal string. The difference is, split() is slower. Cheers Simon Garner -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Parsing a string
Thanks all!! split() works like a champ!! Todd -- Todd Cary Ariste Software [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Parsing a string
Yes... you can use the explode function. Example: if $item where "Hello,There", $parts[0] would = "Hello" and $parts[1] would = "There". Thanks, Mike Ridinger On Fri, 23 Feb 2001, Todd Cary wrote: > I have a comma delimited string that I need to parse into an array. Is > there a PHP function that will do that ? > > Many thanks.. > > Todd > > -- > Todd Cary > Ariste Software > [EMAIL PROTECTED] > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Parsing a string
On Friday 23 February 2001 15:46, Hardy Merrill wrote: > Look up the "split" and "explode" functions - they both do basically > the same thing. > > $token_list = split(",", $string_to_parse); .. and if that doesn't suffice I can send you a nice'n'powerful CSV parser class :) -- Christian Reiniger LGDC Webmaster (http://sunsite.dk/lgdc/) ...1000100011010101101010110100111010113... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Parsing a string
Mensaje citado por: Todd Cary <[EMAIL PROTECTED]>: > I have a comma delimited string that I need to parse into an array. Is > there a PHP function that will do that ? Did you check the string functions? explode for example? Saludos... ;-) System Administration: It's a dirty job, but someone told I had to do it. - Martín Marqués email: [EMAIL PROTECTED] Santa Fe - Argentinahttp://math.unl.edu.ar/~martin/ Administrador de sistemas en math.unl.edu.ar - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Parsing a string
I believe http://www.php.net/manual/en/function.explode.php is what you're after. HTH Jon -Original Message- From: Todd Cary [mailto:[EMAIL PROTECTED]] Sent: 23 February 2001 14:41 To: [EMAIL PROTECTED] Subject: [PHP] Parsing a string I have a comma delimited string that I need to parse into an array. Is there a PHP function that will do that ? Many thanks.. Todd -- Todd Cary Ariste Software [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] ** 'The information included in this Email is of a confidential nature and is intended only for the addressee. If you are not the intended addressee, any disclosure, copying or distribution by you is prohibited and may be unlawful. Disclosure to any party other than the addressee, whether inadvertent or otherwise is not intended to waive privilege or confidentiality' ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Parsing a string
Look up the "split" and "explode" functions - they both do basically the same thing. $token_list = split(",", $string_to_parse); HTH. -- Hardy Merrill Mission Critical Linux, Inc. http://www.missioncriticallinux.com Todd Cary [[EMAIL PROTECTED]] wrote: > I have a comma delimited string that I need to parse into an array. Is > there a PHP function that will do that ? > > Many thanks.. > > Todd > > -- > Todd Cary > Ariste Software > [EMAIL PROTECTED] > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Parsing a string
I have a comma delimited string that I need to parse into an array. Is there a PHP function that will do that ? Many thanks.. Todd -- Todd Cary Ariste Software [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]