Solved

proper way to strip backslashes from url

Posted on 2009-07-01
3
305 Views
Last Modified: 2012-05-07
I need to know a proper, secure, and proficient way to strip not only front slashes but backslashes as well from a url.

the current code im working with is

define('DOMAIN', rtrim(rtrim($_SERVER['HTTP_HOST'], '/') . dirname($_SERVER['PHP_SELF']), '/'));

but it does not strip backslashes which might appear on wamp setups (windows systems)
0
Comment
Question by:redcable
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
kevin_u earned 500 total points
Comment Utility
define('DOMAIN', rtrim(rtrim($_SERVER['HTTP_HOST'], '/\\') . dirname($_SERVER['PHP_SELF']), '/\\'));


That will strip trailing / or \... but I'm not sure if thats what you wanted.
0
 

Author Comment

by:redcable
Comment Utility
define('DOMAIN', rtrim(rtrim($_SERVER['HTTP_HOST'], '/\\') . dirname($_SERVER['PHP_SELF']), '/\\'));

ahh ok i was close. thanks any downside to doing it this way?
0
 
LVL 12

Expert Comment

by:kevin_u
Comment Utility
I can't say there's a downside, unless I know what you are trying to accomplish.

What is DOMAIN used for in the rest of the script?

What if the PHP_SELF has back slashses embedded in it instead of just at the end?

A few examples would help me understand the question.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now