How to write slash ?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
Minouch
Forum Newbie
Posts: 9
Joined: Thu Sep 12, 2013 1:39 pm

How to write slash ?

Post by Minouch »

Hello;

I don't know how to write slash, this code strip slash i don't understand why :

Code: Select all

echo "<link rel=\"stylesheet\" href=\"op/css/op.css\" type=\"text/css\" \/>"; // Doesn't work
echo "<link rel=\"stylesheet\" href=\"op/css/op.css\" type=\"text/css\" />"; // Doesn't work
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How to write slash ?

Post by Celauran »

Can you elaborate on "doesn't work"? They work fine for me.
Minouch
Forum Newbie
Posts: 9
Joined: Thu Sep 12, 2013 1:39 pm

Re: How to write slash ?

Post by Minouch »

For my case, Apache on ubuntu localhost. I get this :

Code: Select all

<link rel="stylesheet" href="op/css/op.css" type="text/css" >
But what i want is this :

Code: Select all

<link rel="stylesheet" href="op/css/op.css" type="text/css" />
The lake of this slash causes the file op.css to not load so i don't get its content anymore. This slash is mandatory but why it didn't work in my case :banghead: i don't understand why ...
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How to write slash ?

Post by Celauran »

Not only is it not mandatory but for HTML5, it's wrong. That aside, this works fine:

Code: Select all

echo "<link rel=\"stylesheet\" href=\"op/css/op.css\" type=\"text/css\" />"; // Doesn't work
You could also wrap it in single quotes to avoid having to escape quotes all over the place.

Code: Select all

 echo '<link rel="stylesheet" href="op/css/op.css" type="text/css" />';
Minouch
Forum Newbie
Posts: 9
Joined: Thu Sep 12, 2013 1:39 pm

Re: How to write slash ?

Post by Minouch »

Hello;
After analyzing my entire source code. It appear that the problem is from a function which strip the slash. Here is the example :

Code: Select all

$link = '<link rel="stylesheet" href="op/css/op.css" type="text/css" />';
$html = '<html xmlns ... </html>'; // Entire web page content.
addbeforehead($html, $link); // Here is the problem, the function add the link just before </head> tag but it always remove the slash
function addbeforehead(&$document, $content){
        $dom = new DOMdocument();
        @$dom->loadHTML($document);
        $xpath = new DOMXPath($dom);
        $head = $xpath->query('//head')->item(0);
        $appendme = new DOMCdataSection($content);
        $head->appendChild($appendme);
        return $dom->saveHTML();
}
So the problem is where in this case ?
Minouch
Forum Newbie
Posts: 9
Joined: Thu Sep 12, 2013 1:39 pm

Re: How to write slash ?

Post by Minouch »

Okay, i got it. Thank you for your help.
Post Reply