You are viewing our Forum Archives. To view or take place in current topics click here.
PHP/HTML - URL Help
Posted:

PHP/HTML - URL HelpPosted:

Craig
  • Discord Elite
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17066
Motto: 2b || !2b
Motto: 2b || !2b
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17066
Motto: 2b || !2b
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.

[ Register or Signin to view external links. ]
#2. Posted:
-Deano
  • Rated Awesome
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
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.
[ Register or Signin to view external links. ]
#3. Posted:
Craig
  • Rated Awesome
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17066
Motto: 2b || !2b
Motto: 2b || !2b
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17066
Motto: 2b || !2b
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:
[ Register or Signin to view external links. ]
#4. Posted:
-Deano
  • Rated Awesome
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Are you unable to rename your images?
#5. Posted:
Deftones
  • Fairy Master
Status: Offline
Joined: May 16, 201311Year Member
Posts: 8,525
Reputation Power: 1554
Status: Offline
Joined: May 16, 201311Year Member
Posts: 8,525
Reputation Power: 1554
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 2021
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17066
Motto: 2b || !2b
Motto: 2b || !2b
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17066
Motto: 2b || !2b
-Deano wrote Are 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
  • PC Master Race
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
In that case, use [ Register or Signin to view external links. ] .
You supply the string to convert to a URL encoded string.

Also use [ Register or Signin to view external links. ] to convert back, if necessary.
#8. Posted:
lamronsavage
  • New Member
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
Craig wrote
-Deano wrote Are 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()
[ Register or Signin to view external links. ]

no need for FANCY shit like -deano want u to use
#9. Posted:
-Deano
  • PC Master Race
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
lamronsavage wrote
uhhh
urlencode()
urldecode()
[ Register or Signin to view external links. ]

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
  • Spooky Poster
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17066
Motto: 2b || !2b
Motto: 2b || !2b
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17066
Motto: 2b || !2b
Either one I wouldn't mind, but how the hell i integrate it with the code above, is still beyond me xD
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.