Escaping quotes PHP echo [duplicate] - php

This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 5 years ago.
I'm having some weird problem escaping " in an echo function.
echo "Site";
Any idea what I'm doing wrong?

You are doing it the javascript way for one. Concatenating in PHP works using . or ,.
Then you are using to many "
Try this line:
echo "Site";

Related

Getting A non-numeric value when combining strings PHP [duplicate]

This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 2 years ago.
I have this code:
echo "<p>" + $username + "<\/p>"
and $username is a string. I get this error:
Warning: A non-numeric value encountered
I don't know why i get this. How can i fix this?
Use "." instead of "+" to concat strings, "+" is only for Arithmetics.

Echo HTML not working because of double quote? [duplicate]

This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 4 years ago.
I know that in this code:
echo '<button style="width:100%;"class="uk-button" data-uk-modal="{target:#my-id'}">Kurstermine anzeigen</button>';
this: data-uk-modal="{target:#my-id'}" causes that any other code below won't run. But how can I fix it? I already tried fixing it by adding \ before the " but this doesn't change the behavior of the error.
<?php
echo <<<EOT
<button style="width:100%;"class="uk-button" data-uk-modal="{target:#my-id'}">Kurstermine anzeigen</button>
EOT;

What's wrong with my way of using filter_input? [duplicate]

This question already has answers here:
PHP's filter_input() strips $_SERVER data on external host, but works on localhost
(2 answers)
Closed 6 years ago.
I am told that I should use filter_input rather than accessing $_SERVER directly
So I made this simple 2 line of code
echo "filter:input " . filter_input(INPUT_SERVER,'REMOTE_ADDR');
echo "SERVER:" .$_SERVER['REMOTE_ADDR'] ;
Very simple. I expect they both produce the exact same thing.
This is what I got
filter:input SERVER:202.80.212.17
Clearly filter_input(INPUT_SERVER,'REMOTE_ADDR') produces empty string.
Why?
It has been a bug in older versions of php. You can either use
echo "filter:input " . filter_input(INPUT_ENV, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
Or use
echo "filter:input " . filter_input($_SERVER['REMOTE_ADDR']);

I am not sure php inside [duplicate]

This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 6 years ago.
Ya here is my code.
<?php print "<?php echo $this->lang('learn_cn')?>" ?>
It comes with blank nothing show.
<?php echo $this->lang('learn_cn')?>
What is the correct way to make this work. TY
You're already in the process of printing out HTML, so just escape that part like you did in the href:
<?php print "" . $this->lang('learn_cn') . "" ?>

Whats faster: echo or print? - PHP [duplicate]

This question already has answers here:
Reference: Comparing PHP's print and echo
(2 answers)
Closed 7 years ago.
Which statement should I be using in PHP? Print or Echo?
In PHP, Echo and Print do the same thing.
Whats the difference? is one of them faster?
Thanks!!
This is a duplicate. Please refer to:
How are echo and print different in PHP?

Categories