remove quotation mark from string output in header

Hi. I’m trying to use the following code in a pages header, and lets say the config file is set to $colourscheme=“pink”

[php][/php]

Some browsers (like Chrome) return “templates/pink/style.css”, which is exactly what I want, but most others return “templates/“pink”/style.css”, which fails.

I have done much searching, but not having much luck - all help appreciated, and thanks in advance.

I try this using:
[php]<?php echo ''; ?>[/php]

Doesn’t it depend on what is inside the variable $colourscheme, I mean how it is loaded?
If it contains the quotes, it will still display them. I don’t think it is a browser issue as much as a data issue inside
the variable. Not sure!?!

I think this is spot on, Chrome probably just fixes it automagically.

OP, try this:

[php]<link href=“templates/<?= trim($colourscheme, '"') ?>/style.css” rel=“stylesheet” type=“text/css” />[/php]

Note that the <?= is just a short hand echo.

Hi Again,
Thanks for the replies. I tried all suggestions so far this morning and sadly, none of them worked. I am still getting those blasted quotation marks, and the stylesheet isn’t loading.

Am I coming at this the right way? Or is there another way to load a stylesheet from a string?
Greg

There shouldn’t be any problems with what you’re doing.

What does this output?

[php]var_dump($colourscheme);[/php]

JimL, I like that " automagically " … Funny!

And, yes, this <?= trim($colourscheme, '"') ?> should trim out the quotes. I am wondering if Gruff noticed that
it is single-quote/double-quote/single-quote… ?

Thanks for helping me with this - I really appreciate it. I did notice the single/double/single quote, I also copied and pasted both suggestions to avoid errors…no luck. It is still coming back as:

<link href="templates/“pink”/style.css" rel="stylesheet" type="text/css" />

Greg

Well Greg, change the line:

To the following and let us know what it displays for you: [php] <?PHP // First, dump the variable: echo "
current value of colourscheme: " . $colourscheme; echo "
dump the true value in case it is not a string: "; print_r($colourscheme); echo "
Now echo what it should be:
"; echo ''; die("
Done!
"); ?> [/php] This is just off the top of my mind, but, it should display all of the possible parts that this point in your page. And, then should die so you can see what is inside everything. Please post back what it displays... Thanks!

The page displayed the following ErnieAlex:

current value of colourscheme: “pink”
dump the true value in case it is not a string: “pink”
Now echo what it should be:

Done!

The page source came back as:

<br>current value of colourscheme: “pink”<br>dump the true value in case it is not a string: “pink”<br>Now echo what it should be:<br><link href="templates/“pink”/style.css" rel="stylesheet" type="text/css" /><br>Done!<br>

That’s a different set of quotes.

[size=24pt]"[/size] vs [size=24pt][/size]

Change my example to

[php][/php]

How is this value assigned? It would be best to avoid these quotes from the beginning.

Okay, now we see your errors! The PINK is clothed not by quotes! You have what is sometimes called “magic”
quotes. This means that your server has the “magic quotes” enabled.

To remove those for display, try this:
[php]

/style.css" rel="stylesheet" type="text/css" /> [/php]

Close JimL - Your code returned:

<link href="templates/�pink/style.css" rel="stylesheet" type="text/css" />

ErnieAlex - Still no different:

<link href="templates/“pink”/style.css" rel="stylesheet" type="text/css" />

You need to do some exploration yourself as well.

Hint:
[size=24pt]“pink”[/size]

Those are two different quotes ^^

[hr]

I’d still recommend fixing this wherever that value is coming from. Why have those weird quotes there anyway?

Well, to remove ALL quotes, try this:
[php]

<?PHP $colourscheme= str_replace("'",''); $colourscheme= str_replace('"',''); $colourscheme= str_replace("`",''); ?> /style.css" rel="stylesheet" type="text/css" /> [/php]

EDIT: Sorry, JimL, I didn’t read your last post before hitting send!
Also, you can shut “magic quotes” off on the server using PHP. Here is the link:
http://php.net/manual/en/security.magicquotes.disabling.php

So I think what you are telling me JimL is I should try:

<link href="templates/<?= trim($colourscheme, '“”') ?>/style.css" rel="stylesheet" type="text/css" />

;D
Looks good on IE, Chrome and Firefox on Windows - Cant try Safari until tonight, but I think you may have solved it for me! Thanks HEAPS JimL

Yes, so give him some Karma… LOL

Yes that was exactly what I was “saying” ^^

Though I still think you should avoid getting these quotes in the first place.

Already Done ErnieAlex! Thanks again JimL!

Sponsor our Newsletter | Privacy Policy | Terms of Service