I am not sure php inside [duplicate] - php

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') . "" ?>

Related

Escaping quotes PHP echo [duplicate]

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";

Echoing variable in php [duplicate]

This question already has answers here:
How to enable PHP short tags?
(21 answers)
Closed 6 years ago.
Essentially I am trying to have a heading using what is below. Not sure what is going on but nothing happens. Even when I do something as simple as echo "hello" there instead of the 2 variables.
<h1><?echo "$info[0] ($info[1])";?></h1>
You can use <?= ?> shorthand for echoing variables and the code should look like,
<h1><?= "$info[0] ($info[1])"; ?></h1>
Try using this way. You are missing <?php.
<h1> <?php echo $info[0] .'('. $info[1] .')'; ?> </h1>

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?

How can i echo total of both variables as expected? [duplicate]

This question already has answers here:
PHP string number concatenation messed up
(5 answers)
Closed 8 years ago.
I wrote a simple script for echoing total of two variables to <h1> tag, but it gives strange results
<?php
$i=10; $j=20;
var_dump($i);
var_dump($j);
echo '<h1>'.$i+$j.'</h1>';
?>
Result of this script:
int(10)
int(20)
20</h1>
I was expecting 30 but it ate up <h1> tag, how can i do this as expected?
Try this:
echo '<h1>'.($i+$j).'</h1>';
This explains why you need to concatenate like this. Here is a working demo.

Why I am not able to echo 'sort=name<string>'? [duplicate]

This question already has answers here:
'Why' doesn't the script print anything? [duplicate]
(5 answers)
Closed 9 years ago.
This is a weird issue.
I just trying to print/create a string like below :
sort="name<string>"
so I just do
echo 'sort="name<string>"';
however, it seems that PHP store it as :
sort="name"
What do I miss?
Try this...
echo htmlspecialchars('sort="name<string>"', ENT_QUOTES, 'UTF-8');
Try this:
echo 'sort="name<String>"';

Categories