Jump to content

urlencode()


doddsey_65

Recommended Posts

im using urlencode() to replace special characters in the url. It works on spacs, replacing them with '+' but it isnt working on a special character i have tried, the exclamation mark. Is this the right function to use for this? and if so why isnt it working for me?

 

function create_url($str)
{
    $str = urlencode($str);
    return $str;
}

function decode_url($str)
{
    $str = urldecode($str);
    return $str;
}

 

i use the function create_url() for the link and use decode_url() when the link is clicked so i can display the proper name.

 

eg:

 

$forum_url_name = create_url($row['f_name']);

 

and when viewing the forum:

 

$forum_name = decode_url($_GET['f_name']);

 

Link to comment
Share on other sites

You typically do not need to urldecode a value from $_GET, because a single urldecoding pass is applied by PHP automatically.  You would only need to urldecode it if it got double url encoded in the first place.

 

As for why it's not working, I will need to see the full code, or a small sample code which demonstrates the problem.

Link to comment
Share on other sites

basically:

 

the url reads like asimpleforum.co.uk/post/sample_post!

 

so

 

<a href="asimpleforum.co.uk/post/sample_post!">

 

htaccess is used so the actual url points to view_post.php?post_name=sample_post!

 

that is how you access the post.

 

When you click the link to view the post i run a query to get all of the post information but the query is run from the post name.

 

so posts with a space are replaced with an underscore etc.

 

The only problem is that using the ! in a url breaks it and sends a 404 error "page not found"

 

so i tried using str_replace to replace the ! with %21. This threw the same 404 error.

 

the same thing happened with urlencode.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.