On 08 November 2007 06:41, Ron Croonenberg wrote:
> ok I wrote something "quick and dirty" real quick:
>
> But somehow it doesn't seem to like recursion. Is there something
> "special" one needs to do in php ?
Recursive functions work just fine in PHP. What's the error message?
As far as I can see, there's nothing wrong with what you've posted, except for
where there's some inefficiency due to not having found the right functions to
use (see corrections below).
>
> here's the code snippet:
>
> function parsehtmlline($line)
> {
> if (strlen(strstr($line, "#include")) == 0 &&
> strlen(strstr($line, "<!--")) == 0) {
if (strpos($line, "#include")===FALSE && strpos($line, "<!--")===FALSE)
> /* nothing to parse just print it */
> print($line);
> }
> else {
> /* extract the filename */
> $ssi = extractHTMLssi($line);
>
> /* open the file if it exists and output */
> /* it else just print the string */
> if (file_exists($ssi)) {
> $incfile = fopen($ssi, "r");
> while (!feof($incfile)) {
> $ssiline = fgets($incfile, 1024);
> // somehow PhP doesn't really like recursion, needs to be fixed
> // for now just print the line.
> // parsehtmlline($ssiline);
> print($ssiline);
> }
> fclose($incfile);
> }
> else
> print($ssi);
> }
> }
>
> function extractHTMLssi($line)
> {
> $ssi = "";
> $strptr = strstr($line, "\"");
> if (strlen($strptr) == 0)
> return $line;
> else
> {
> $ssi=$strptr;
> $iss=strrev($ssi);
> $strptr = strstr($iss, "\"");
> $iss = substr($strptr, 1, -1);
> $ssi = strrev($iss);
> }
>
> return $ssi;
I'd replace the whole of this function body with something like:
$pos = strpos($line, '"');
if ($strpos===FALSE):
return $line;
else:
return substr($line, $pos+1, strrpos($line, '"')-1);
endif;
> }
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
JG125, The Headingley Library,
James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 812 4730 Fax: +44 113 812 3211
To view the terms under which this email is distributed, please go to
http://disclaimer.leedsmet.ac.uk/email.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php