Page 1 of 1

How to write slash ?

Posted: Thu Sep 12, 2013 1:43 pm
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

Re: How to write slash ?

Posted: Thu Sep 12, 2013 3:06 pm
by Celauran
Can you elaborate on "doesn't work"? They work fine for me.

Re: How to write slash ?

Posted: Thu Sep 12, 2013 3:50 pm
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 ...

Re: How to write slash ?

Posted: Thu Sep 12, 2013 4:50 pm
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" />';

Re: How to write slash ?

Posted: Thu Sep 12, 2013 5:17 pm
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 ?

Re: How to write slash ?

Posted: Thu Sep 12, 2013 5:32 pm
by Minouch
Okay, i got it. Thank you for your help.