Re: [PHP] Help with Strings Please
* and then Marek Kilimajer declared > >Im not very good at regex, is there an function that would help me? > >(couldnt see one...) > > > > preg_match('/value\s*=\s*"([0-9]+)"/i', $buffer, $result); > print ("Result:".$result[1]); Marek, you're a star ;-) I *hate* having to ask someone to do my work, "mastering regular expressions' in going on my christmas wish list! hehe... thanks again... PS: Justin, got it covered. Thanks.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with Strings Please
From: "Marek Kilimajer" <[EMAIL PROTECTED]> $handle = fopen("page.php", "r"); while (!feof($handle)) { $buffer .= fgets($handle, 4096); } fclose($handle); file_get_contents() could be helpful here, too... ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with Strings Please
Nick, Nick wrote: I have a string like this, read from an html file: ' VALUE="16">' The value could be any number. I am trying to get that number. If you have that exact string and you want to extract just the number, then a simple regex to delete all non-numeric characters should suffice. I have this so far, i was hoping someone might tell me how to get that number: $handle = fopen("page.php", "r"); while (!feof($handle)) { $buffer .= fgets($handle, 4096); } fclose($handle); $result = stristr($buffer, 'NAME="c"'); print ("Result:".$result); ?> Ok, so I don't see ' VALUE="16">' in here anywhere -- I think you need to be a lot more descriptive about the source content and what exactly you want to extract, and provide a few examples, so that we can cover all your bases. Regular Expressions are _probably_ what you need, but you REALLY need to provide a decent description and multiple examples of what you want, otherwise we're just wasting time. --- Justin French http://indent.com.au -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with Strings Please
Nick Wilson wrote: Hi, I have a string like this, read from an html file: ' VALUE="16">' The value could be any number. I am trying to get that number. I have this so far, i was hoping someone might tell me how to get that number: $handle = fopen("page.php", "r"); while (!feof($handle)) { $buffer .= fgets($handle, 4096); } fclose($handle); $result = stristr($buffer, 'NAME="c"'); print ("Result:".$result); ?> Im not very good at regex, is there an function that would help me? (couldnt see one...) thx... preg_match('/value\s*=\s*"([0-9]+)"/i', $buffer, $result); print ("Result:".$result[1]); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help with strings...
Not sure what your goal is here but the easiest (and most efficient) way to get the first character of a string is : $string = 'abcdef'; print $string{0}; // prints a print $string{3}; // prints d So in your case, maybe the following craziness is what you're wanting : ${$string{0}} = 'crazy'; print $a; // prints crazy Regards, Philip Olson On Fri, 31 Aug 2001, Papp Gyozo wrote: > > $GLOBALS[substr($string, 0, 1)] > or : > > $tmp = substr($string, 0, 1); > ${$tmp} = 'add whatever value you want'; > > - Original Message - > From: Stig-Ørjan Smelror <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Friday, August 31, 2001 9:35 AM > Subject: [PHP] help with strings... > > > > Hei all. > > > > I've got this string, $string = "test"; and I want to make a $t; out of > > $string. > > Is this possible? > > > > I tried ${substr($string, 0, 1)}, but that didn't work ;) > > > > > > Any help appreciated. > > > > > > TIA. > > -- > > Stig-Ørjan Smelror > > Systemutvikler > > > > Linux Communications AS > > Sandakerveien 48b > > Box 1801 - Vika > > N-0123 Oslo, Norway > > > > tel. +47 22 09 28 80 > > fax. +47 22 09 28 81 > > http://www.lincom.no/ > > > > > > -- > > 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 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] help with strings...
$GLOBALS[substr($string, 0, 1)] or : $tmp = substr($string, 0, 1); ${$tmp} = 'add whatever value you want'; - Original Message - From: Stig-Ørjan Smelror <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, August 31, 2001 9:35 AM Subject: [PHP] help with strings... > Hei all. > > I've got this string, $string = "test"; and I want to make a $t; out of > $string. > Is this possible? > > I tried ${substr($string, 0, 1)}, but that didn't work ;) > > > Any help appreciated. > > > TIA. > -- > Stig-Ørjan Smelror > Systemutvikler > > Linux Communications AS > Sandakerveien 48b > Box 1801 - Vika > N-0123 Oslo, Norway > > tel. +47 22 09 28 80 > fax. +47 22 09 28 81 > http://www.lincom.no/ > > > -- > 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]