amwd07 Posted August 15, 2007 Share Posted August 15, 2007 Hello I have finally got the spaces to replace with - in php but although the page now links there seems to be no output here if I remove the - and put in %20 the page comes up fine it also work with using + instead of space can someone please help with this MYSQL coding or maybe soemthing in htaccess needs to be defined? this work for a hyperlink but when the can't find page http://www.madeinshropshire.co.uk/demo/index.php?title=about+us (this works) http://www.madeinshropshire.co.uk/demo/index.php?title=about%20us (this works) http://www.madeinshropshire.co.uk/demo/index.php?title=about-us (this needs to work) $title=mysql_result($result1,$i,"title"); $sef = stringForUrl($title); example link <a href=index.php?title=$sef>$title</a> <?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; } $sef = stringForUrl($title); ?> Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/ Share on other sites More sharing options...
amwd07 Posted August 15, 2007 Author Share Posted August 15, 2007 can anyone help with this today please? Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-324433 Share on other sites More sharing options...
amwd07 Posted August 15, 2007 Author Share Posted August 15, 2007 am I alone on this one please someone must know a thingor 2 about this ??? Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-324897 Share on other sites More sharing options...
MadTechie Posted August 15, 2007 Share Posted August 15, 2007 change $allowed = '/[^a-z0-9 ]/ims'; to $allowed = '/[^a-z0-9 -]/ims'; Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-324961 Share on other sites More sharing options...
amwd07 Posted August 15, 2007 Author Share Posted August 15, 2007 Thank you for your reply but that did not work here is my code below as you can see it is working here http://www.madeinshropshire.co.uk/demo/index.php?title=about+us but when I try to use about-us through the link created <a href=index.php?title=$sef>$title</a> it shows the correct url but no output from the page do I need something else to get this to work? <?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; } ?> $content_id=mysql_result($result1,$i,"content_id"); $title=mysql_result($result1,$i,"title"); $desc=mysql_result($result1,$i,"desc"); $sef = stringForUrl($title); //////////////////////////////////////////////////////// $site_title = "Made In Shropshire Demo Site"; $page_title = "$title"; $main .= "<a href=index.php?title=$sef>$title</a><hr>$desc"; Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-324984 Share on other sites More sharing options...
amwd07 Posted August 15, 2007 Author Share Posted August 15, 2007 can anyone have an idea for a solution maybe a HTACCESS rule to read + as - (about-us) but not (about+us) Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325157 Share on other sites More sharing options...
MadTechie Posted August 15, 2007 Share Posted August 15, 2007 change $allowed = '/[^a-z0-9 ]/ims'; to $allowed = '/[^a-z0-9 -+]/ims'; as a note you did say it worked for + http://www.madeinshropshire.co.uk/demo/index.php?title=about+us (this works) http://www.madeinshropshire.co.uk/demo/index.php?title=about%20us (this works) http://www.madeinshropshire.co.uk/demo/index.php?title=about-us (this needs to work) Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325205 Share on other sites More sharing options...
amwd07 Posted August 15, 2007 Author Share Posted August 15, 2007 Sorry I think you may be missing the point the url already reads http://www.madeinshropshire.co.uk/demo/index.php?title=about-us so the function is correct but there is no output from the DB although this does give an output http://www.madeinshropshire.co.uk/demo/index.php?title=about+us Please I need the site to work with - Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325212 Share on other sites More sharing options...
MadTechie Posted August 15, 2007 Share Posted August 15, 2007 You lost me.. whats the problem ? Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325217 Share on other sites More sharing options...
amwd07 Posted August 15, 2007 Author Share Posted August 15, 2007 simple this should work? click the link the page is blank but if you replace the - with + it comes up? http://www.madeinshropshire.co.uk/demo/index.php?title=about-us Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325227 Share on other sites More sharing options...
MadTechie Posted August 15, 2007 Share Posted August 15, 2007 OK total guess but add $strOut = str_replace('-', '+', $strOut); //Add above // swap spaces for _ $strOut = str_replace(' ', '-', $strOut); //<-- you have this note sure why your swapping things around Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325234 Share on other sites More sharing options...
cooldude832 Posted August 15, 2007 Share Posted August 15, 2007 you notice how spaces becoem %20 try finding the code for the - and replacing that with it. every character has ones I believe even alphanumerics Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325244 Share on other sites More sharing options...
amwd07 Posted August 15, 2007 Author Share Posted August 15, 2007 I see what your saying but this only work for the link $strOut don't i need to have something so the url remains the same but the page queries about%20us from the DB %20 is th esame as the plus this is why this already works. maybe this can't be done in PHP or do I need some kind of htaccess rule all I want to do is take out those annoying spaces and replace them with ever hypen or underscore shouln't be to difficult should it? example of URL from another site Craven%20Arms%20Hotel (Craven+Arms+Hotel) this would work but is no good to me this would be much more friendly craven-arms-hotel or (craven_arms_hotel) Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325255 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 OK as i am now more lots then when we started, can you explain what your trying to do an why ? i think you want a link with a cleaned up tag.. but your changing the link.. ? ??? Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325267 Share on other sites More sharing options...
amwd07 Posted August 16, 2007 Author Share Posted August 16, 2007 OK I will try and simplify this the current url shows up the content id 1 from database about us this is how it is written in the database and is also used for the menu on the left for dynamic updatable links Now the link in index.php <a href=index.php?title=$sef>$title</a> sef refers to $sef = stringForUrl($title); (title is coming from here) $title=mysql_result($result1,$i,"title"); No when you click about us from the menu on the left notice the url is http://www.madeinshropshire.co.uk/demo/index.php?title=about+us (this is without the function) now if you click the title about us and not the navigation link you will notice the URL changes to http://www.madeinshropshire.co.uk/demo/index.php?title=about-us (this is using the function) this is axactly what I wanted to happen the function works the way it should but now the problem is about us is not being found from the DB this is because there is a space in the name, I don't want to change anything in the database or the url I just need to have the same output as this url http://www.madeinshropshire.co.uk/demo/index.php?title=about-us once this is working I can create a HTACCESS rule to convert the new SEF URL to http://www.madeinshropshire.co.uk/about-us/ Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325283 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 sorry still makes no sense, if you change the URL to one that doesn't work it.. it will not work! you should be changing the title not the link the very fact your filtering output from the database and then trying to link back via that data confuses me.. sorry either i have failed to understand what you are trying to do or your logic is incorrect.. Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325290 Share on other sites More sharing options...
amwd07 Posted August 16, 2007 Author Share Posted August 16, 2007 OK tak the working page http://www.madeinshropshire.co.uk/demo/index.php?title=about+us for example the contents of the page is correct the url now is wrong all I need to do is change the + to - but when I do the contents disapears ??? All I need is Search Engine Friendly Urls Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325299 Share on other sites More sharing options...
MadTechie Posted August 16, 2007 Share Posted August 16, 2007 what about this? http://www.madeinshropshire.co.uk/demo/index.php?contents=about-us&title=about+us or http://www.madeinshropshire.co.uk/demo/index.php?title=about-us&title=about+us Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325303 Share on other sites More sharing options...
amwd07 Posted August 16, 2007 Author Share Posted August 16, 2007 what about this? http://www.madeinshropshire.co.uk/demo/index.php?contents=about-us&title=about+us or http://www.madeinshropshire.co.uk/demo/index.php?title=about-us&title=about+us yes this would work I can stip down the url in HTACCESS to read like this http://www.madeinshropshire.co.uk/demo/about-us but my question is how do I get the htaccess to ignore the title? any if it does ignor ewill th epage still show with the contents? Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325310 Share on other sites More sharing options...
amwd07 Posted August 16, 2007 Author Share Posted August 16, 2007 this now works http://www.madeinshropshire.co.uk/demo/about+us.html using this in the htaccess file is there someway i can replace + with - in htaccess? Options +FollowSymLinks RewriteEngine on RewriteRule (.*)\.html index.php?title=$1 Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325325 Share on other sites More sharing options...
amwd07 Posted August 16, 2007 Author Share Posted August 16, 2007 I have also seen this sollution on another forum but can't get it to work? # replace spaces with hyphens rewriterule ^([^\ ]*)\ (.*)$ $1-$2 [E=rspace:yes,N] # Redirect to update URL in search engine listings and browsers RewriteCond %{ENV:rspace} yes rewriterule (.*) http://%{HTTP_HOST}$1 [R=301,L] Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-325326 Share on other sites More sharing options...
amwd07 Posted August 16, 2007 Author Share Posted August 16, 2007 help ??? Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-326138 Share on other sites More sharing options...
amwd07 Posted August 17, 2007 Author Share Posted August 17, 2007 anyone know how to work with htaccess as above ??? Quote Link to comment https://forums.phpfreaks.com/topic/64963-sef-urls/#findComment-326360 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.