125369
125369

Reputation: 3657

URL for the pdf file using PHP

I am trying to generate an URL for my pdf file stored on my localhost. I dynamically retrieve the pdf name and append it to the path of the folder where the pdf is stored and store the url in a variable which I wanted to use later.

My code follows like this:

    $pdf = 'data.pdf';
    $path = "H:\xampp\htdocs\testing\ ";
    $path_replaced = str_replace(" ", "", $path);
    $url = $path_replaced . $pdf;
    echo $url;

but unfortunately instead of getting "H:\xampp\htdocs\testing\data.pdf", I am getting this as output "H: mpp\htdocs esting\0023.pdf "

Any reason why this is happening!

Thanks

Upvotes: 1

Views: 443

Answers (4)

Christopher Bull
Christopher Bull

Reputation: 2629

Use single quotes (') to store your string.

You are using back-slashes "\" which when used within double quotes are recognised as special characters when combined with letters (i.e. "\n" = new line, or "\t" = tab).

Upvotes: 1

Jan Dragsbaek
Jan Dragsbaek

Reputation: 8101

This is happening because you have \t in your path, which funny enough equals to a tab. You should. When defining something like this, you should always use single-quotes, like this:

$path = 'H:\xampp\htdocs\testing\ ';

Upvotes: 0

Marcus
Marcus

Reputation: 12586

\t is a tab-character and thus you need to escape the string. Or use single quotes ' instead of double quotes:

$path = 'H:\xampp\htdocs\testing\ ';

Upvotes: 1

Haim Evgi
Haim Evgi

Reputation: 125446

change to

 $path = 'H:\xampp\htdocs\testing\ ';

If the string is enclosed in double-quotes ("), PHP will interpret more escape sequences for special characters like \t

look on http://li.php.net/manual/en/language.types.string.php#language.types.string.syntax.double

Upvotes: 1

Related Questions