Re: Finding one line in a Variable?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
To: "php-general" <php-general@xxxxxxxxxxxxx>
Sent: Monday, October 11, 2004 3:45 AM
Subject: 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


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux