FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » decode encoded url
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
decode encoded url [message #178675] Tue, 17 July 2012 05:47 Go to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
Hi,

I have a url that refers to a css background like:
url(./sites/all/themes/marinelli/img/backgrounds/men's_and_ladys&a mp;#039;_nights.jpg);
But now I'm wondering how I possibly should name that file or how i can decode this string to a url the filesystem & the browser can read?

Thanks for help!
Ron
Re: decode encoded url [message #178676 is a reply to message #178675] Tue, 17 July 2012 07:00 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
cerr wrote:

> I have a url that refers to a css background like:
> url(./sites/all/themes/marinelli/img/backgrounds/men's_and_ladys&a mp;#039;_nights.jpg);
> But now I'm wondering how I possibly should name that file or how i can decode this string to a url the filesystem& the browser can read?

The browser does it for you.


--

//Aho
Re: decode encoded url [message #178678 is a reply to message #178675] Tue, 17 July 2012 07:52 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 17/07/2012 7:47, cerr escribió/wrote:
> I have a url that refers to a css background like:
> url(./sites/all/themes/marinelli/img/backgrounds/men's_and_ladys&a mp;#039;_nights.jpg);
> But now I'm wondering how I possibly should name that file or how i can decode this string to a url the filesystem & the browser can read?

If the string is supposed to be HTML, you need to convert it into plain
text. It can be extremaly tricky becase the two most obvious functions
don't seem to work as advertised:

http://es.php.net/manual/en/function.html-entity-decode.php
http://es.php.net/manual/en/function.htmlspecialchars-decode.php

Another alternative is to use mb_convert_encoding():

<?php
$html =
'url(./sites/all/themes/marinelli/img/backgrounds/men&#039;s_and_ladys& amp;#039;_nights.jpg);';
var_dump(mb_convert_encoding($html, 'UTF-8', 'HTML-ENTITIES'));

Then, it's pretty straightforward to create the file.


If the string is supposed to be plain text already, I see no problem.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: decode encoded url [message #178689 is a reply to message #178678] Tue, 17 July 2012 13:04 Go to previous messageGo to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
On Tuesday, July 17, 2012 12:52:53 AM UTC-7, Álvaro G. Vicario wrote:
> El 17/07/2012 7:47, cerr escribió/wrote:
> &gt; I have a url that refers to a css background like:
> &gt; url(./sites/all/themes/marinelli/img/backgrounds/men&amp;#039;s_and_lad ys&amp;#039;_nights.jpg);
> &gt; But now I&#39;m wondering how I possibly should name that file or how i can decode this string to a url the filesystem &amp; the browser can read?
>
> If the string is supposed to be HTML, you need to convert it into plain
> text. It can be extremaly tricky becase the two most obvious functions
> don&#39;t seem to work as advertised:
>
> http://es.php.net/manual/en/function.html-entity-decode.php
> http://es.php.net/manual/en/function.htmlspecialchars-decode.php
>
> Another alternative is to use mb_convert_encoding():
>
> &lt;?php
> $html =
> &#39;url(./sites/all/themes/marinelli/img/backgrounds/men&amp;#039; s_and_ladys&amp;#039;_nights.jpg);&#39;;
> var_dump(mb_convert_encoding($html, &#39;UTF-8&#39;, &#39;HTML-ENTITIES&#39;));

This doesn't work for me, I got some error:
<b>Parse error</b>: syntax error, unexpected '=', expecting ')' in <b> /homepages/9/d412202464/htdocs/drupal-7.14/sites/all/themes/marinelli/templ ates/html.tpl.php </b> on line <b>17</b><br />

>
> Then, it&#39;s pretty straightforward to create the file.
>
>
> If the string is supposed to be plain text already, I see no problem.

It wouldn't link a file called
men&#039;s_and_ladys&#039;_nights.jpg nor
men's_and_ladys'_nights.jpg

>
>
> --
> -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programación web: http://borrame.com
> -- Mi web de humor satinado: http://www.demogracia.com
> --
Re: decode encoded url [message #178690 is a reply to message #178678] Tue, 17 July 2012 13:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/17/2012 3:52 AM, "Álvaro G. Vicario" wrote:
> El 17/07/2012 7:47, cerr escribió/wrote:
>> I have a url that refers to a css background like:
>> url(./sites/all/themes/marinelli/img/backgrounds/men&#039;s_and_ladys&a mp;#039;_nights.jpg);
>>
>> But now I'm wondering how I possibly should name that file or how i
>> can decode this string to a url the filesystem & the browser can read?
>
> If the string is supposed to be HTML, you need to convert it into plain
> text. It can be extremaly tricky becase the two most obvious functions
> don't seem to work as advertised:
>
> http://es.php.net/manual/en/function.html-entity-decode.php
> http://es.php.net/manual/en/function.htmlspecialchars-decode.php
>
> Another alternative is to use mb_convert_encoding():
>
> <?php
> $html =
> 'url(./sites/all/themes/marinelli/img/backgrounds/men&#039;s_and_ladys& amp;#039;_nights.jpg);';
>
> var_dump(mb_convert_encoding($html, 'UTF-8', 'HTML-ENTITIES'));
>
> Then, it's pretty straightforward to create the file.
>
>
> If the string is supposed to be plain text already, I see no problem.
>
>

It's a URL, so the correct function to use would be urldecode().

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: decode encoded url [message #178691 is a reply to message #178690] Tue, 17 July 2012 13:57 Go to previous messageGo to next message
cerr is currently offline  cerr
Messages: 33
Registered: September 2010
Karma: 0
Member
On Tuesday, July 17, 2012 6:08:05 AM UTC-7, Jerry Stuckle wrote:
> On 7/17/2012 3:52 AM, &quot;�lvaro G. Vicario&quot; wrote:
> &gt; El 17/07/2012 7:47, cerr escribi�/wrote:
> &gt;&gt; I have a url that refers to a css background like:
> &gt;&gt; url(./sites/all/themes/marinelli/img/backgrounds/men&amp;#039;s_and_lad ys&amp;#039;_nights.jpg);
> &gt;&gt;
> &gt;&gt; But now I&#39;m wondering how I possibly should name that file or how i
> &gt;&gt; can decode this string to a url the filesystem &amp; the browser can read?
> &gt;
> &gt; If the string is supposed to be HTML, you need to convert it into plain
> &gt; text. It can be extremaly tricky becase the two most obvious functions
> &gt; don&#39;t seem to work as advertised:
> &gt;
> &gt; http://es.php.net/manual/en/function.html-entity-decode.php
> &gt; http://es.php.net/manual/en/function.htmlspecialchars-decode.php
> &gt;
> &gt; Another alternative is to use mb_convert_encoding():
> &gt;
> &gt; &lt;?php
> &gt; $html =
> &gt; &#39;url(./sites/all/themes/marinelli/img/backgrounds/men&amp;#039; s_and_ladys&amp;#039;_nights.jpg);&#39;;
> &gt;
> &gt; var_dump(mb_convert_encoding($html, &#39;UTF-8&#39;, &#39;HTML-ENTITIES&#39;));
> &gt;
> &gt; Then, it&#39;s pretty straightforward to create the file.
> &gt;
> &gt;
> &gt; If the string is supposed to be plain text already, I see no problem..
> &gt;
> &gt;
>
> It&#39;s a URL, so the correct function to use would be urldecode().

But when I name the file
men&#039;s_and_ladys&#039;_nights.jpg (what erldecode() gives me), it doesn't work...
Re: decode encoded url [message #178692 is a reply to message #178691] Tue, 17 July 2012 14:17 Go to previous messageGo to next message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma: 0
Senior Member
On 7/17/2012 3:57 PM, cerr wrote:
> On Tuesday, July 17, 2012 6:08:05 AM UTC-7, Jerry Stuckle wrote:
>> On 7/17/2012 3:52 AM, &quot;�lvaro G. Vicario&quot; wrote:
>> &gt; El 17/07/2012 7:47, cerr escribi�/wrote:
>> &gt;&gt; I have a url that refers to a css background like:
>> &gt;&gt; url(./sites/all/themes/marinelli/img/backgrounds/men&amp;#039;s_and_lad ys&amp;#039;_nights.jpg);
>> &gt;&gt;
>> &gt;&gt; But now I&#39;m wondering how I possibly should name that file or how i
>> &gt;&gt; can decode this string to a url the filesystem &amp; the browser can read?
>> &gt;
>> &gt; If the string is supposed to be HTML, you need to convert it into plain
>> &gt; text. It can be extremaly tricky becase the two most obvious functions
>> &gt; don&#39;t seem to work as advertised:
>> &gt;
>> &gt; http://es.php.net/manual/en/function.html-entity-decode.php
>> &gt; http://es.php.net/manual/en/function.htmlspecialchars-decode.php
>> &gt;
>> &gt; Another alternative is to use mb_convert_encoding():
>> &gt;
>> &gt; &lt;?php
>> &gt; $html =
>> &gt; &#39;url(./sites/all/themes/marinelli/img/backgrounds/men&amp;#039; s_and_ladys&amp;#039;_nights.jpg);&#39;;
>> &gt;
>> &gt; var_dump(mb_convert_encoding($html, &#39;UTF-8&#39;, &#39;HTML-ENTITIES&#39;));
>> &gt;
>> &gt; Then, it&#39;s pretty straightforward to create the file.
>> &gt;
>> &gt;
>> &gt; If the string is supposed to be plain text already, I see no problem.
>> &gt;
>> &gt;
>>
>> It&#39;s a URL, so the correct function to use would be urldecode().
>
> But when I name the file
> men&#039;s_and_ladys&#039;_nights.jpg (what erldecode() gives me), it doesn't work...
>


The string was 2 times encoded.
Try to decode it again.
echo urldecode("men&#039;s_and_ladys&#039;_nights.jpg");
gives
men's_and_ladys'_nights.jpg

I wonder why it was encoded like that?

Regards,
Erwin Moller

--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
Re: decode encoded url [message #178693 is a reply to message #178690] Tue, 17 July 2012 15:18 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Jerry Stuckle)

> On 7/17/2012 3:52 AM, "Álvaro G. Vicario" wrote:
>> El 17/07/2012 7:47, cerr escribió/wrote:
>>> I have a url that refers to a css background like:
>>> url(./sites/all/themes/marinelli/img/backgrounds/men&#039;s_and_ladys&a mp;#039;_nights.jpg);
>>>
>>> But now I'm wondering how I possibly should name that file or how i
>>> can decode this string to a url the filesystem & the browser can read?
>>
>> If the string is supposed to be HTML, you need to convert it into plain
>> text. It can be extremaly tricky becase the two most obvious functions
>> don't seem to work as advertised:
>>
>> http://es.php.net/manual/en/function.html-entity-decode.php
>> http://es.php.net/manual/en/function.htmlspecialchars-decode.php
>>
>> Another alternative is to use mb_convert_encoding():
>>
>> <?php
>> $html =
>> 'url(./sites/all/themes/marinelli/img/backgrounds/men&#039;s_and_ladys& amp;#039;_nights.jpg);';
>>
>> var_dump(mb_convert_encoding($html, 'UTF-8', 'HTML-ENTITIES'));
>>
>> Then, it's pretty straightforward to create the file.
>>
>>
>> If the string is supposed to be plain text already, I see no problem.
>>
>>
>
> It's a URL, so the correct function to use would be urldecode().

This is not a URL encoding, but HTML character references.

Micha

--
http://mfesser.de/
Fotos | Blog | Flohmarkt
Re: decode encoded url [message #178694 is a reply to message #178692] Tue, 17 July 2012 14:56 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
On Tue, 17 Jul 2012 16:17:45 +0200, Erwin Moller wrote:
> On 7/17/2012 3:57 PM, cerr wrote:
>> On Tuesday, July 17, 2012 6:08:05 AM UTC-7, Jerry Stuckle wrote:
>>> On 7/17/2012 3:52 AM, &quot;???lvaro G. Vicario&quot; wrote:
>>> &gt; El 17/07/2012 7:47, cerr escribi???/wrote:
>>> &gt;&gt; I have a url that refers to a css background like:
>>> &gt;&gt; url(./sites/all/themes/marinelli/img/backgrounds/men&amp;#039;s_and_lad ys&amp;#039;_nights.jpg);
>>> &gt;&gt;
>>> &gt;&gt; But now I&#39;m wondering how I possibly should name that file or how i
>>> &gt;&gt; can decode this string to a url the filesystem &amp; the browser can read?
>>> &gt;
>>> &gt; If the string is supposed to be HTML, you need to convert it into plain
>>> &gt; text. It can be extremaly tricky becase the two most obvious functions
>>> &gt; don&#39;t seem to work as advertised:
>>> &gt;
>>> &gt; http://es.php.net/manual/en/function.html-entity-decode.php
>>> &gt; http://es.php.net/manual/en/function.htmlspecialchars-decode.php
>>> &gt;
>>> &gt; Another alternative is to use mb_convert_encoding():
>>> &gt;
>>> &gt; &lt;?php
>>> &gt; $html =
>>> &gt; &#39;url(./sites/all/themes/marinelli/img/backgrounds/men&amp;#039; s_and_ladys&amp;#039;_nights.jpg);&#39;;
>>> &gt;
>>> &gt; var_dump(mb_convert_encoding($html, &#39;UTF-8&#39;, &#39;HTML-ENTITIES&#39;));
>>> &gt;
>>> &gt; Then, it&#39;s pretty straightforward to create the file.
>>> &gt;
>>> &gt;
>>> &gt; If the string is supposed to be plain text already, I see no problem.
>>> &gt;
>>> &gt;
>>>
>>> It&#39;s a URL, so the correct function to use would be urldecode().
>>
>> But when I name the file
>> men&#039;s_and_ladys&#039;_nights.jpg (what erldecode() gives me), it doesn't work...
>>
>
>
> The string was 2 times encoded.
> Try to decode it again.
> echo urldecode("men&#039;s_and_ladys&#039;_nights.jpg");
> gives
> men's_and_ladys'_nights.jpg
>
> I wonder why it was encoded like that?

Heh. You've SEEN what his editor does to quoting, and the lack of
concern exhibited over it... The double-encoding might well have been
caused just PASTING the single-encoded text.

--
_ o
|/)
Re: decode encoded url [message #178697 is a reply to message #178689] Tue, 17 July 2012 15:41 Go to previous messageGo to next message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma: 0
Member
cerr wrote:
> It wouldn't link a file called
> men&#039;s_and_ladys&#039;_nights.jpg nor
> men's_and_ladys'_nights.jpg

That's a strange file name, but you can link to it in (X)HTML by
applying htmlspecialchars() to it, e.g.:

<a href="<?php echo
htmlspecialchars('men&#039;s_and_ladys&#039;_nights.jpg') ?>">Men's and
Ladys' Nights</a>

--
Christoph M. Becker
Re: decode encoded url [message #178698 is a reply to message #178693] Tue, 17 July 2012 19:26 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/17/2012 11:18 AM, Michael Fesser wrote:
> .oO(Jerry Stuckle)
>
>> On 7/17/2012 3:52 AM, "Álvaro G. Vicario" wrote:
>>> El 17/07/2012 7:47, cerr escribió/wrote:
>>>> I have a url that refers to a css background like:
>>>> url(./sites/all/themes/marinelli/img/backgrounds/men&#039;s_and_ladys&a mp;#039;_nights.jpg);
>>>>
>>>> But now I'm wondering how I possibly should name that file or how i
>>>> can decode this string to a url the filesystem & the browser can read?
>>>
>>> If the string is supposed to be HTML, you need to convert it into plain
>>> text. It can be extremaly tricky becase the two most obvious functions
>>> don't seem to work as advertised:
>>>
>>> http://es.php.net/manual/en/function.html-entity-decode.php
>>> http://es.php.net/manual/en/function.htmlspecialchars-decode.php
>>>
>>> Another alternative is to use mb_convert_encoding():
>>>
>>> <?php
>>> $html =
>>> 'url(./sites/all/themes/marinelli/img/backgrounds/men&#039;s_and_ladys& amp;#039;_nights.jpg);';
>>>
>>> var_dump(mb_convert_encoding($html, 'UTF-8', 'HTML-ENTITIES'));
>>>
>>> Then, it's pretty straightforward to create the file.
>>>
>>>
>>> If the string is supposed to be plain text already, I see no problem.
>>>
>>>
>>
>> It's a URL, so the correct function to use would be urldecode().
>
> This is not a URL encoding, but HTML character references.
>
> Micha
>

Ah, you're right. I got caught up in the fact it was in a URL.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: decode encoded url [message #178699 is a reply to message #178689] Wed, 18 July 2012 08:29 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 17/07/2012 15:04, cerr escribió/wrote:
> On Tuesday, July 17, 2012 12:52:53 AM UTC-7, Álvaro G. Vicario wrote:
>> El 17/07/2012 7:47, cerr escribió/wrote:
>> &gt; I have a url that refers to a css background like:
>> &gt; url(./sites/all/themes/marinelli/img/backgrounds/men&amp;#039;s_and_lad ys&amp;#039;_nights.jpg);
>> &gt; But now I&#39;m wondering how I possibly should name that file or how i can decode this string to a url the filesystem &amp; the browser can read?
>>
>> If the string is supposed to be HTML, you need to convert it into plain
>> text. It can be extremaly tricky becase the two most obvious functions
>> don&#39;t seem to work as advertised:
>>
>> http://es.php.net/manual/en/function.html-entity-decode.php
>> http://es.php.net/manual/en/function.htmlspecialchars-decode.php
>>
>> Another alternative is to use mb_convert_encoding():
>>
>> &lt;?php
>> $html =
>> &#39;url(./sites/all/themes/marinelli/img/backgrounds/men&amp;#039; s_and_ladys&amp;#039;_nights.jpg);&#39;;
>> var_dump(mb_convert_encoding($html, &#39;UTF-8&#39;, &#39;HTML-ENTITIES&#39;));
>
> This doesn't work for me, I got some error:
> <b>Parse error</b>: syntax error, unexpected '=', expecting ')' in <b> /homepages/9/d412202464/htdocs/drupal-7.14/sites/all/themes/marinelli/templ ates/html.tpl.php </b> on line <b>17</b><br />

I wonder what code you are actually running, given that my snippet has
somehow grown HTML entities when you've quoted in your answer, but
that's a good old syntax error. Can't you really fix it?

>> If the string is supposed to be plain text already, I see no problem.
>
> It wouldn't link a file called
> men&#039;s_and_ladys&#039;_nights.jpg nor
> men's_and_ladys'_nights.jpg

I beg your pardon? If the string is plain text, you don't have single
quotes anywhere: you have literal & characters.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: PHP Always Outputs
Next Topic: PHP Rear End Data Developer/ Contract/ Boston area
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 07:49:56 GMT 2024

Total time taken to generate the page: 0.02498 seconds