ProgrammingPHP/HTML - URL HelpPosted:

Craig
  • Gold Member +
Status: Offline
Joined: Jan 16, 20126 Year Member
Posts: 17,769
Reputation Power: 1618
Motto: hi!
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,928
Reputation Power: 428
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
  • Christmas!
Status: Offline
Joined: Jan 16, 20126 Year Member
Posts: 17,769
Reputation Power: 1618
Motto: hi!
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:
i.imgur.com/vIJu6bx.png
#4. Posted:
-Deano
  • Rated Awesome
Status: Offline
Joined: Aug 19, 20107 Year Member
Posts: 4,928
Reputation Power: 428
Are you unable to rename your images?
#5. Posted:
ZTG
  • 5K Undisputed
Status: Offline
Joined: May 16, 20134 Year Member
Posts: 7,932
Reputation Power: 571
Motto: i hate my username
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
  • 15k Juggernaut
Status: Offline
Joined: Jan 16, 20126 Year Member
Posts: 17,769
Reputation Power: 1618
Motto: hi!
-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,928
Reputation Power: 428
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:
Status: Offline
Joined: Feb 25, 20161 Year Member
Posts: 17
Reputation Power: 12
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...encode.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,928
Reputation Power: 428
lamronsavage wrote
uhhh
urlencode()
urldecode()
php.net/manual/ro/function...encode.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
  • Supporter
Status: Offline
Joined: Jan 16, 20126 Year Member
Posts: 17,769
Reputation Power: 1618
Motto: hi!
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