Re: Finding one line in a Variable?
| From: | Minuk Choi | Date: | Mon, 11 Oct 2004 09:09:44 +0000 |
| Subject: | Re: Finding one line in a Variable? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-199157@lists.php.net to get a copy of this message | ||
If you don't mind NOT using regex or regular expression searching commands, you can try it this way.
Assuming that there is a carriage break(e.g. "\r\n" if windows, and I'm assuming the HTML file was written in windows, otherwise, just "\n" for Unix and "\n\r" for Mac, I believe).
$eolnString ="\r\n";
$searchString = "the_identifying_string";
$result="NOT FOUND";
$HTMLDumpArray = explode($eolnString, $myHTML);
/*
if $myHTML = "<HTML>\r\n\t<BODY>\r\n\t</BODY>\r\n</HTML>";
then
$HTMLDumpArray is now
$HTMLDumpArray[0] = "<HTML>";
$HTMLDumpArray[1] = "\t<BODY>";
$HTMLDumpArray[2] = "\t</BODY>";
$HTMLDumpArray[3] = "</HTML>";
*/
foreach ($HTMLDumpArray as $HTMLLine)
if (stripos($HTMLLine, $searchString)!==FALSE)
//stripos returns the index number of where the $searchString was found OR returns FALSE
{
$result = $HTMLLine;
break;
}
echo "RESULT ".$result;
try that and let me know if that works.
HTH,
-Minuk
----- Original Message ----- From: "Nick Wilson" <nick@stylesheet.org>
To: "php-general" <php-general@lists.php.net>
Sent: Monday, October 11, 2004 3:45 AM
Subject: [PHP] Finding one line in a Variable?
Hello all, I have to find and put one line of an html file in a variable. I already have the entire html file stored in a variable like this: $myHTML="<html><head>blah blah blah"; - Grabbed using cURL The particular line I want will *always* contain the string "the_identifying_string" So the line itself (the line i want to get into a var) would look like this: <form method="post" action="blah.php" name="the_identifying_string" blah..> How can I get that entire line? many thanks, im sure your all bored of my regex woes heh.. but thanks, it's appreciated.. -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php