ProgrammingPHP/HTML - URL HelpPosted:

Craig
  • Winter 2017
Status: Offline
Joined: Jan 16, 20125 Year Member
Posts: 17,362
Reputation Power: 1510
Motto: Hello Party People! This Is Captain Kim Speaking... Welcome Aboard Venga Airways... After Take Off Will Pump Up The Soundsystem, Cause We're Going To Ibiza!!!! I Don't Wanna Be A Busdriver.... All My Life
So, I'm a little stuck on what to do and hope some of the clever folks around here can solve my issue.

I have setup a simple page to display all the images that use a .jpg extension in a certain directory, which works fine for my needs apart from one thing. I cannot seem to get my head around how to implement a URL encode/decode for the symbols (i.e # \ / and spaces).

How would I go about implementing some sort of URL encode that is automatic, in the code below.

Thanks.

Sorry for Pastebin link but can't post PHP on forums.

pastebin.com/krQGhPQ3
#2. Posted:
-Deano
  • Rated Awesome
Status: Offline
Joined: Aug 19, 20107 Year Member
Posts: 4,896
Reputation Power: 426
Motto: Thanks to Prodigy for the gold! | PCMR
I'm a bit confused on exactly what you are asking here (Are you trying to just decode from the directory or handle both encode/decode?)

The htmlentities() function might be of use to you.
Reference
#3. Posted:
Craig
  • Winter 2017
Status: Offline
Joined: Jan 16, 20125 Year Member
Posts: 17,362
Reputation Power: 1510
Motto: Hello Party People! This Is Captain Kim Speaking... Welcome Aboard Venga Airways... After Take Off Will Pump Up The Soundsystem, Cause We're Going To Ibiza!!!! I Don't Wanna Be A Busdriver.... All My Life
I don't really understand it myself, but I'll try to explain as best I can.

I have a image file in a directory that I would like to display on a web page, which works fine for files that have the regular names. But when it comes to files with # or < > in the name, it fails to display.

htmlEntities sounds like what I need or PHP String Replace, not sure which would be better.

EDIT:
https://i.imgur.com/vIJu6bx.png
#4. Posted:
-Deano
  • Rated Awesome
Status: Offline
Joined: Aug 19, 20107 Year Member
Posts: 4,896
Reputation Power: 426
Motto: Thanks to Prodigy for the gold! | PCMR
Are you unable to rename your images?
#5. Posted:
ZTG
  • Winter 2017
Status: Offline
Joined: May 16, 20134 Year Member
Posts: 7,888
Reputation Power: 569
Motto: "ur gey" - Grohl
I'm barely educated on PHP, but wouldn't this be PHP String Replace of some sorts? If I were you I would just change the image's file name and go from there because it's a much easier solution than practically almost rebuilding
#6. Posted:
Craig
  • Winter 2017
Status: Offline
Joined: Jan 16, 20125 Year Member
Posts: 17,362
Reputation Power: 1510
Motto: Hello Party People! This Is Captain Kim Speaking... Welcome Aboard Venga Airways... After Take Off Will Pump Up The Soundsystem, Cause We're Going To Ibiza!!!! I Don't Wanna Be A Busdriver.... All My Life
-Deano wroteAre you unable to rename your images?
I am yes, but since new images are added very frequently under pre made names, renaming them is out of the options list for this use case.

I think I'm missing a small bit of code to automatically convert # to %23 which in turn, works perfectly.
#7. Posted:
-Deano
  • Rated Awesome
Status: Offline
Joined: Aug 19, 20107 Year Member
Posts: 4,896
Reputation Power: 426
Motto: Thanks to Prodigy for the gold! | PCMR
In that case, use RawURLEncode.
You supply the string to convert to a URL encoded string.

Also use RawURLDecode to convert back, if necessary.
#8. Posted:
lamronsavage
  • Gold Member
Status: Offline
Joined: Feb 25, 20161 Year Member
Posts: 16
Reputation Power: 12
Motto: rememba da name
Craig wrote
-Deano wroteAre you unable to rename your images?
I am yes, but since new images are added very frequently under pre made names, renaming them is out of the options list for this use case.

I think I'm missing a small bit of code to automatically convert # to %23 which in turn, works perfectly.

uhhh
urlencode()
urldecode()
php.net/manual/ro/function.urlencode.php

no need for FANCY shit like -deano want u to use
#9. Posted:
-Deano
  • Rated Awesome
Status: Offline
Joined: Aug 19, 20107 Year Member
Posts: 4,896
Reputation Power: 426
Motto: Thanks to Prodigy for the gold! | PCMR
lamronsavage wrote
uhhh
urlencode()
urldecode()
php.net/manual/ro/function.urlencode.php

no need for FANCY shit like -deano want u to use


I mean, I suggested rawurlencode() and you think that's fancy shit?
It's literally the same as what you are suggesting, except spaces are also converted to %20 instead of a +...
#10. Posted:
Craig
  • Winter 2017
Status: Offline
Joined: Jan 16, 20125 Year Member
Posts: 17,362
Reputation Power: 1510
Motto: Hello Party People! This Is Captain Kim Speaking... Welcome Aboard Venga Airways... After Take Off Will Pump Up The Soundsystem, Cause We're Going To Ibiza!!!! I Don't Wanna Be A Busdriver.... All My Life
Either one I wouldn't mind, but how the hell i integrate it with the code above, is still beyond me xD
Users browsing this topic: None
Jump to:


RECENT POSTS

HOT TOPICS