Hello, I have some PHP code that goes to an article site, strips articles, places it in a template, copies it to my website and creates an index page of all the files it creates.
The code takes the name of the article and makes that the name of the HTML file, it replaces the spaces between the words with an underscore (so it will work as a URL). It would take the article title:
I Like To Fly Model Airplanes (In The Dark)!
and makes it:
I_Like_To_Fly_Model_Airplanes_(In_The_Dark)!.html
I would like to take this a bit further, I would like to change the uppercase letters to lowercase letters (in the HTML title):
i_like_to_fly_model_airplanes_(in_the_dark)!.html
I would also like to remove any characters that don't translate well into HTML:
~!@#$%&*()+=\/?.,][}{:;"
i_like_to_fly_model_airplanes_in_the_dark.html
And I would like to remove words that aren't necessary in the HTML title, these just add excess length:
to, the, it, and, or, with, too, also, an, in, if, a, i
like_fly_model_airplanes_dark.html
Here is the part of the code that deals with replacing the spaces with underscores:
//SAVE THE ARTICLE INFO TO THE DB
if(put_article($data)==true){//echo"article saved to DB<br>";
}
}
function save_article($html,$title)
{//echo "saving $title<br>";
global $save_dir;
$filename=substr(str_replace(" ","_",$title),0,20).".html";
//$path=$save_dir.$filename;
//echo $filename."path<br>";
if (!write_file($html,$filename)) {echo "cant save file:$filename. ";return false;}
else {return $filename;}
}
I have tried adding the line:
// convert to lowercase
$filename=strtolower($title);
right after the line
$filename=substr(str_replace(" ","_",$title),0,20).".html";
to convert the uppercase to lower case, it doesn't work, I know practically nothing about PHP, I can do HTML though, any help on this would be greatly appreciated.
Thanks in advance
Wretha