Sorry for jumping the gun and making assumptions earlier.
I have tried losing the ignore and copy-pasteing to debug it.
Here's the non-includified source code:
welcome.php
PHP Code:
<?php
function makeParas($txtfile) {
$fullpath = 'http://'.$HTTP_SERVER_VARS[HTTP_HOST].$HTTP_SERVER_VARS[REQUEST_URI];
$thisfile = basename($fullpath);
$cutoffpos = strpos($fullpath,$thisfile);
$thisdir = substr($fullpath, 0, $cutoffpos);
// $thisdir is the full path minus filename incluing trailing slash:
// "www.mysite.com/thisdir/"
if (!$txtfile) {
// no text file [error]
return "<p>error msg here</p>";
}
else {
$path2paras = $thisdir.$txtfile;
$content_array = file($path2paras);
$content = implode("",$content_array);
$paras = explode("{",$content);
foreach ($paras as $value) {
$lencssclass = strstr($value,"}")-1;
if ($lencssclass > 0) {
$cssclass = substr($value,"1",$lencssclass);
$paratxt = substr($value,$lencssclass+2);
$parasrc .= "<p class=\"".$cssclass."\">".$paratxt."</p>\n";
}
else {
$paratxt = substr($value,2);
$parasrc .= "<p>".$paratxt."</p>\n";
}
}
return $parasrc;
}
}
echo makeParas("welcome.p");
?>
welcome.p
Code:
{cssclass1}first para with cssclass1 as it's css class.
{}second para with no css class associated
{}again no css class
{bigtext}fat text
(NB: In source is all one line but I added linebreaks so as not to stretch the screen)
errors
Warning: file("welcome.p") - No such file or directory in C:\phpdev\www\public\includes\content\welcome.php on line 17
Warning: Bad arguments to implode() in C:\phpdev\www\public\includes\content\welcome.php on line 18
I'll try to explain the script.
1. welcome.p is a text file defining the text to put into paragraphs and for some paras, a css class to apply to them.
2. the script opens the above text file and implodes it into one long string (for convenience) and then explodes it by the character { (the start of every para's configuration).
3. for each seperate part of the array (read: each paragraph):
4. if $cssclasslen (the number of chars between {} ) is non-zero, then get the chars between the curly brackets and make the start tag (including class="cssclass"). Then get the rest of the text (the content) and add it between the start tag and an end tag. append this para to $parasrc
5. if $cssclasslen is zero, there is no class so just get the text and sandwich it between "<p>" and "</p>". append this para to $parasrc
6. return $parasrc - the code for all the paras.
I know you may say this is a pointless excersise - "why don't you just make welcome.p contain HTML code?" - but I chose to do it this way, and I'd like to make it work... purely to see where i went wrong so I don't do it again. Thanks.