0

I try to use ascii letters in my url-site but I don't know what i use ascii letters ( è , é , à, ect.. ) in my url. I try to use urlencode\urldecode but i can't view my page when i use a ascii letters. I don't know what resolve this problem. Can you help me with an example pls ?

function my_url($offer) {
$dd = url_title($offer->number." ".$offer->number,"-",true);
return site_url("siteweb\view".$offer->number."/".urlencode($dd));

My problem is in "urlencode($dd)"

update

    function my_url($offer) {
$dd = url_title($offer->number." ".$offer->number,"-",true);
$ddd= rawurldecode($ddd)
return site_url("siteweb\view".$offer->number."/".htmlspecialchars($ddd));
Phantom Moore
  • 41
  • 1
  • 8

1 Answers1

-1

I think what you're looking for is htmlentities

"htmlentities — Convert all applicable characters to HTML entities"

Lulceltech
  • 1,662
  • 11
  • 22
  • How does that help in the context of URL? – Dharman Mar 25 '19 at 20:16
  • You should use htmlentities in url's too.. goto the link I posted and look at example #2. https://www.php.net/manual/en/function.urlencode.php – Lulceltech Mar 25 '19 at 20:17
  • Clearly you did not read the manual then, straight from example #2: echo ''; – Lulceltech Mar 25 '19 at 20:20
  • But in this way i can't use ( example: -olè) in my url 'cause it became : mysite.it/ol%E3%A9 I want use -olè – Phantom Moore Mar 25 '19 at 20:21
  • You need to decode it afterwards before trying to display it. – Lulceltech Mar 25 '19 at 20:23
  • mmm.. how can i do ? – Phantom Moore Mar 25 '19 at 20:25
  • ok, now I am intrigued, why does the [manual](https://www.php.net/manual/en/function.urlencode.php) suggest to use both? – Dharman Mar 25 '19 at 20:28
  • @PhantomMoore https://www.php.net/manual/en/function.html-entity-decode.php – Lulceltech Mar 25 '19 at 20:30
  • @Dharman its because they do different things in the same way, html encode escapes them but leaves them understandable to html, while url encode takes it escapes it and makes it understandable to url's. It depends on your use case really. – Lulceltech Mar 25 '19 at 20:32
  • I get that, it is just I have never seen them both used together, or in any combination. I cannot think of any reason to use both of them. As you said `htmlentities` has a different purpose than `urlencode` – Dharman Mar 25 '19 at 20:35
  • And for this case where he's trying to print the data back htmlentities works better. However you can use them together in unique cases. There's a good article on here somewhere, when I find it i'll link back to it. – Lulceltech Mar 25 '19 at 20:36
  • [URL/HTML Escaping/Encoding](https://stackoverflow.com/a/4783070/1839439) - Also check the comment under the second answer. – Dharman Mar 25 '19 at 20:46
  • If i use htmlentities i don't see anymore my url >.> – Phantom Moore Mar 25 '19 at 21:00