Forum Moderators: coopster

Message Too Old, No Replies

SEF URLs request blank?

the links work

         

amwd07

1:30 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



OK this works the one way through the link but
when the page come up nothing shows, don't I need something to decode the other end?

example

this works
http://www.example.co.uk/demo/content.php?title=about%20us

this doesn't but links correctly
http://www.example.co.uk/demo/content.php?title=about-us

here is my page belwow
I feel I'm so close on this one yet so far

$query="SELECT * FROM content WHERE title='$title'";
$result=mysql_query($query);
mysql_close();

function stringForUrl($strIn) {
$strOut = $strIn;
$allowed = '/[^a-z0-9 ]/ims';

// only alphanum and spaces allowed
$strOut = preg_replace($allowed, '', $strOut);

// swap spaces for _
$strOut = str_replace(' ', '-', $strOut);
$strIn = str_replace('-', ' ', $strIn);

// make lower case for consistancy
$strOut = strtolower($strOut);

return $strOut;
}

$content_id=mysql_result($result,$i,"content_id");
$title=mysql_result($result,$i,"title");
$desc=mysql_result($result,$i,"desc");
$sef = stringForUrl($title);

///////////////////////////////////////////////////////////////////////////////////////////

$site_title = "My Website";
$page_title = "Sample Template 3 Content Page 1";
$main .= "<a href=content.php?title=$sef>$title</a><br>$desc<hr>";

require('include/header.php');
require('include/strapline.php');
require('include/main_menu.php');
require('include/footer.php');

// First we read the contents of the template.php file as the variable $template.
$template = file_get_contents('include/template.php');

// Now we do a search and replace on $template inserting content where the keywords were placed
// We do this with 2 arrays, one for search and one for replace.
// We then use the preg_replace function to make the changes and create an output variable

$search = array('¦{PAGE_TITLE}¦',
'¦{MAIN_MENU}¦',
'¦{MAIN}¦',
'¦{HEADER}¦',
'¦{FOOTER}¦',
'¦{STRAPLINE}¦'

);
$replace = array("$site_title - $page_title",
$main_menu,
$main,
$header,
$footer,
$strapline
);

$output = preg_replace($search, $replace, $template);

echo $output;
?>

[edited by: jatar_k at 4:14 pm (utc) on Aug. 10, 2007]
[edit reason] no urls thanks [/edit]

PHP_Chimp

3:41 pm on Aug 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you are replacing the - for a %20 (space) further down the code than the SELECT statement.

So at the SELECT statement the about%20us and about-us are sent as 2 different pages i.e. looking for 2 different pages in database. If you want users to be able to get the page both ways then move your str_replace up to the top of your code then the spaces and - will be converted before the SELECT statement.

amwd07

4:12 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



IF ONLY IT WAS THAT SIMPLE
is there something else I'm missing here?

<?php require('include/connection.php');

function stringForUrl($strIn) {
$strOut = $strIn;
$allowed = '/[^a-z0-9 ]/ims';

// only alphanum and spaces allowed
$strOut = preg_replace($allowed, '', $strOut);

// swap spaces for _
$strOut = str_replace(' ', '-', $strOut);

// make lower case for consistancy
$strOut = strtolower($strOut);

return $strOut;
}

$query="SELECT * FROM content WHERE title='$title'";
$result=mysql_query($query);
mysql_close();

$content_id=mysql_result($result,$i,"content_id");
$title=mysql_result($result,$i,"title");
$desc=mysql_result($result,$i,"desc");
$sef = stringForUrl($title);

amwd07

11:04 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



is there something needed in htaccess or can I do this with php it shows correctly on link but does not output on page please help someone?