Is it possible to...

Status
Not open for further replies.

rgordon83

it's a wig
Dec 27, 2007
1,310
28
0
www.tribe9interactive.com
i have a URL where i am dynamically inserting a field to go to a specific page on a site. Problem is that in order to get to a page on the site with multiple words, there needs to be an underscore between them

So

ThisIsAReallyGaySite.com/Keyword_Here (inserted with PHP <?=$kw$> )

My current URL links like this.

Mysite.com?kw=Keyword Here

I don't use the underscore in the URL b/c i also dynamically insert the keyword on the page as well, so underscore would look bad. So any two or more word keyword is not going to the right page b/c there is no underscore

So my question is, is there a way to automatically convert spaces in an outbound URL in underscores?

So
ThisIsAReallyGaySite.com/Keywords Here

would become

ThisIsAReallyGaySite.com/Keywords_Here


thanks!
 


It'd probably make more sense to send the input with the underscore in the query, and then strip it out on the insertion into the page, rather than the other way around.
 
Code:
<?php
$keyword = str_replace($keyword, "_", " ");
?>

I didn't actually test this, but if you insert that into your code you can link to domain.com/keyword_here and it will be replaced with "keyword here" in the output for the user.
 
PHP:
<?php
$keyword = str_replace("%20", "_", $_POST['kw']); // Replaces converted spaces to underscores
$keyword = str_replace("_", " ", $_POST['kw']); // Replaces underscores to spaces
?>
Not sure why you would want to do that, just use the above PHP and then strip out all weird characters to make sure people don't inject and that should work.
 
i would like to suggest a site planetsource.com there a lot of code and tags there, just search for programming language you like

This guy really comes off as a spammer with everything he posts. He usually says nothing at all in his posts, posts on outdated threads like this, and now posts to a parked page url... Mods?
 
Status
Not open for further replies.