Hello,
I am new here and to PHP coding. I just want to say thank you in advance to anyone who is nice enough to take the time to help me out.
I recently created a news article program that lets the user create a new article for a website and then it creates a webpage from a template.
It takes the actual date and adds it to the filename for the url of the article, and it works great so far. But Google prefers that news articles actually have the title/subject of article in the url. I can make the subject go into the file name but because of the spaces and maybe other non url friendly characters, it gives me an error.
I can find all over the net examples of string replace and understand how it’s done. What I am not able to do is take what I programmed already and convert the user inputted title into the URL string.
Below is a piece of the code and how it works now. What I need help with is to take the posted string subject and create a new variable that is a slug of the title/subject and use that instead of the article ID which is the date. If I can just take $subject = $_POST[subject]; and create a new variable called $slug_url which is the subject but with a slug URL friendly string, then I can place it in the filename creation section…
Again thanks in advance and I appreciate it very much!!!
[php] <?
include (“template.inc”);
include (“config.php”);
$subject = $_POST[subject];
$summary = $_POST[summary];
$passwd = $_POST[passwd];
$date = $_POST[date];
$body = $_POST[body];
$article_id = $_POST[article_id];
#foreach($GLOBALS as $a => $b){ print "<li>$a => $b";}
$summary_template = "t_summary.html";
$article_template = "t_article.html";
$max_summary = 5;
function summary_page ($subject, $date, $summary, $article_id)
{
global $summary_template;
$t = new Template();
$t->set_file("SummaryPage", $summary_template);
$article_url = "http://www.mydomain.com/articles/NFL/article_NFL_".$article_id.".html";
$date = nl2br($date);
$summary = nl2br($summary);
$t->set_var( array(
"subject" => $subject,
"date" => $date,
"summary" => $summary,
"article_url" => $article_url
));
$t->parse("Summary", "SummaryPage");
return $t->get_var("Summary");
}
function main_page ($subject, $date, $summary, $article_id, $body)[/php]