Solved

proper way to strip backslashes from url

Posted on 2009-07-01
3
309 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
ID: 24758998
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
ID: 24759161
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
ID: 24759690
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

713 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