Jump to content

Strange variable problem (space problem)


frankdm
Go to solution Solved by Psycho,

Recommended Posts

I got the following code:

 

$varproducttitle = get_the_title();
$varcomplete = $vargooglelink . $varproducttitle;
echo $varcomplete;
$content .= "<td> <a href=$varcomplete>test</a> </td>";
 
The echo is just to test, the names in the echo are 100% correct so both variables are filled in as they should.
 
HOWEVER, the $varcomplete only uses the first word of the $varproducttitle in the hyperlink ... again, if i echo &varcomplete or &varproducttitle then in both cases it shows me 100% correct all words.... it is just when I use $varcomplete in the href that it looses any words after the first... I am stumped... I take it has to do with the space between words in &varcomplete (maybe a url doesn't like spaces) but in this case I need those spaces!
Link to comment
Share on other sites

  • Solution

Parameter values (like the href parameter for an anchor tag) should be within quotes so the browser knows where the value starts and ends. If the value is not within quotes it assumes that the first space is the end of the value

 

 

$content .= "<td> <a href='$varcomplete'>test</a> </td>";
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.