cfructose
02-20-2007, 02:23 AM
I'm stumped on 'split' and 'explode'...
Here's what I'm doing: first, I'm putting an include of a data file into a template, but also establishing the varibale $add_content for later use:
$include_name = basename($_SERVER['PHP_SELF']);
$add_content = include ("text/$include_name");
echo $add_content;
So far so good. But now, I want to count how many instances of "</h2>" are in the data of the included file, and then perform an action if the number's less than 4:
$headers = split($add_content, "</h2>");
$number_of_headers = count($headers);
if ($number_of_headers>4) { $long=1; }
if (!($page == "About") || isset($long)) { do something }
I'm guesing my problem is that the array $headers doesn't contain any data from the file "text/basename($_SERVER['PHP_SELF'])", as, when I echo it as a test, it returns "1".
$number_of_headers also returns "1", regardless.
I get the same results using "explode" instead of "split".
If I've understood the concept, then $headers should be an array where [0] = all the data in the file "text/basename($_SERVER['PHP_SELF'])" until the first instance of "</h2>", and [1] contains all the data between the first and second "</h2>"s etc.
...Or have I completely lost the plot...? :-)
Can split/explode actually be used on a variable containing the comand to include a file? If not, is there a way?
Also, how do we explain the returned value of 1 when echoing $headers?
Any guidance very much appreciated.
Here's what I'm doing: first, I'm putting an include of a data file into a template, but also establishing the varibale $add_content for later use:
$include_name = basename($_SERVER['PHP_SELF']);
$add_content = include ("text/$include_name");
echo $add_content;
So far so good. But now, I want to count how many instances of "</h2>" are in the data of the included file, and then perform an action if the number's less than 4:
$headers = split($add_content, "</h2>");
$number_of_headers = count($headers);
if ($number_of_headers>4) { $long=1; }
if (!($page == "About") || isset($long)) { do something }
I'm guesing my problem is that the array $headers doesn't contain any data from the file "text/basename($_SERVER['PHP_SELF'])", as, when I echo it as a test, it returns "1".
$number_of_headers also returns "1", regardless.
I get the same results using "explode" instead of "split".
If I've understood the concept, then $headers should be an array where [0] = all the data in the file "text/basename($_SERVER['PHP_SELF'])" until the first instance of "</h2>", and [1] contains all the data between the first and second "</h2>"s etc.
...Or have I completely lost the plot...? :-)
Can split/explode actually be used on a variable containing the comand to include a file? If not, is there a way?
Also, how do we explain the returned value of 1 when echoing $headers?
Any guidance very much appreciated.