how to use php

ab.chess

New Member
Messages
9
Reaction score
0
Points
1
I was trying to search for "php" and it does not work because the keyword is too short(?).
Anyway, I am new to x10 and I am trying to run a simple script within html page:
-------------------
<html>
<body>
output from php<br>
<?php
print "<p>mr Mc Donalds<br>";
print "Burger!<br>";
print "I'm Loving It!<br>";
?>
</body>
</html>
-----------------
Getting a very strange result:
----
output from php
mr Mc Donalds
"; print "Burger!
"; print "I'm Loving It!
"; ?>
---
It looks like the 1st print uses the rest of the code as the text to print.
Is there a manual about using php on x10?
 

ab.chess

New Member
Messages
9
Reaction score
0
Points
1
Hmm. This is not the answer that I expect. So each 'print' stmt needs to be within its own php tags? When it should only print the text within quote marks? At least that's how it works with my Ubuntu local php (older version).
Why does php ignore the pairing closing quote mark? Any special settings?
 

ctyrd

Active Member
Messages
868
Reaction score
78
Points
28
@ab.chess
Code:
<p>
<?php print
"Mc Donalds <br>
 Burger! <br>
 I'm Loving It!"
 ?>
 </p>

Out put:
Mc Donalds
Burger!
I'm Loving It!

Code:
<p>
<?php echo $geturl; ?><br>
<?php
echo $geturl; // don't forget to define variable for $geturl
print "<br>See the close after the quotation";
print "<br>No close after quotation"
?>
</p>

Out Put:
domain
domain
See the close after the quotation
No close after quotation
 
Last edited:

ab.chess

New Member
Messages
9
Reaction score
0
Points
1
@ab.chess
Code:
<p>
<?php print
"Mc Donalds <br>
 Burger! <br>
 I'm Loving It!"
 ?>
 </p>

Out put:
Mc Donalds
Burger!
I'm Loving It!

Code:
<p>
<?php echo $geturl; ?><br>
<?php
echo $geturl; // don't forget to define variable for $geturl
print "<br>See the close after the quotation";
print "<br>No close after quotation"
?>
</p>

Out Put:
domain
domain
See the close after the quotation
No close after quotation
Nope.
Here is my code:
<body>
<p>
<?php $geturl = "domain"; ?><br>
<?php echo $geturl; ?><br>
<?php
echo $geturl; // don't forget to define variable for $geturl
print "<br>See the close after the quotation";
print "<br>No close after quotation"
?>
</p>
</body>
----------------
the output:


See the close after the quotation"; print "
No close after quotation" ?>
--------
Not only php doesn't recognize the closing quotation mark, but $geturl is empty.
Any suggestions?
 

ctyrd

Active Member
Messages
868
Reaction score
78
Points
28
@ab.chess

Show me a live out put to what your seeing. The file your viewing is not a true html/php document. https://www.ctyrd.org/incdoc/chicks

charset set to utf-8

This is the live out put of the code: https://www.ctyrd.org/chicks

You forgot to define the variable for $geturl!
You changed the first ?php code to echo the word domain incorrectly, should have been:
Code:
<?php echo ('domain'); ?><br>
This:
Code:
<?php echo $geturl; ?><br>
echos the variable you forgot to define.
To define a variable ?php code at the top of the document.
Code:
<?php
$geturl = $_SERVER['HTTP_HOST']; // Defines the variable
$geturl = preg_replace('/^www\./' , '' , $geturl); // Removes http/www.
$geturl = ucfirst($geturl); //Returns a string with the first character of string capitalized NULL
$geturl = strtolower($geturl); //Returns string with all ASCII alphabetic characters converted to lowercase
?>

My index.php file: https://ctyrd.org/index.txt
 
Last edited:

ab.chess

New Member
Messages
9
Reaction score
0
Points
1
@ab.chess

Show me a live out put to what your seeing. The file your viewing is not a true html/php document. https://www.ctyrd.org/incdoc/chicks

charset set to utf-8

This is the live out put of the code: https://www.ctyrd.org/chicks

You forgot to define the variable for $geturl!
You changed the first ?php code to echo the word domain incorrectly, should have been:
Code:
<?php echo ('domain'); ?><br>
This:
Code:
<?php echo $geturl; ?><br>
echos the variable you forgot to define.
To define a variable ?php code at the top of the document.
Code:
<?php
$geturl = $_SERVER['HTTP_HOST']; // Defines the variable
$geturl = preg_replace('/^www\./' , '' , $geturl); // Removes http/www.
$geturl = ucfirst($geturl); //Returns a string with the first character of string capitalized NULL
$geturl = strtolower($geturl); //Returns string with all ASCII alphabetic characters converted to lowercase
?>

My index.php file: https://ctyrd.org/index.txt
I have no clue what you mean.
"You forgot to define the variable for $geturl!"?
what about <?php $geturl = "domain"; ?><br>?
"The file your viewing is not a true html/php document."?
This is the file: https://chesspad.elementfx.com/ping.html
You can see its source there.
 

spacresx

Community Advocate
Community Support
Messages
2,183
Reaction score
195
Points
63
Is there a manual about using php on x10?
x10 does not provide script support, so you will not find any manuals here.
there are websites that provide php help and tutorials.
a simple google search can show many websites with such help.
 

ctyrd

Active Member
Messages
868
Reaction score
78
Points
28
@ab.chess
Your file ping.html should be named "ping.php". php code will not render in a .html or a .txt document. Html markup will render in a .php document.

Code:
<?php $geturl = "domain"; ?><br>
does not define the variable. Read the post again, I showed you how to define the variable. I added it to keep you on your toes.

php is hard to get the hang of, I had to learn php by trial and error. Then the tutorials started to make scene.
 
Last edited:

ab.chess

New Member
Messages
9
Reaction score
0
Points
1
Actually, about 10 years ago I wrote the whole web site using php and I do not recall having issues like these.
Unfortunately your answers do not clear much and create more questions.
So, why
$geturl = $_SERVER['HTTP_HOST']; // Defines the variable
and
$geturl = "domain";
does not?? What's the difference?
I am looking at https://www.php.net/manual/en/language.variables.basics.php and I do not see how my code is different from the examples there.
"php code will not render in a .html"
What about https://www.php.net/manual/en/faq.html.php? Doesn't your statement contradict the manual?
Isn't it how I include php in html?

In fact, your only recommendation:
Your file ping.html should be named "ping.php".
worked.
As soon as I renamed my file, everything started working as I had expected. Nonetheless my questions are still unanswered.
 

spacresx

Community Advocate
Community Support
Messages
2,183
Reaction score
195
Points
63
Actually, about 10 years ago I wrote the whole web site using php and I do not recall having issues like these.
Unfortunately your answers do not clear much and create more questions.
So, why
$geturl = $_SERVER['HTTP_HOST']; // Defines the variable
and
$geturl = "domain";
does not?? What's the difference?
I am looking at https://www.php.net/manual/en/language.variables.basics.php and I do not see how my code is different from the examples there.
"php code will not render in a .html"
What about https://www.php.net/manual/en/faq.html.php? Doesn't your statement contradict the manual?
Isn't it how I include php in html?

In fact, your only recommendation:
Your file ping.html should be named "ping.php".
worked.
As soon as I renamed my file, everything started working as I had expected. Nonetheless my questions are still unanswered.
you mention the code is like 10 years old.
php support changes a lot. thats why you see different versions to run websites. like php 7.4 or php 8.0 etc
so whats written for php 6.0 will not always work in php 8.0 for example. depending on the code used.
some simple yet small scripts may still work but more complex ones do not.

php files need to have the .php extension to work properly. especially with configuration files.

$geturl = $_SERVER['HTTP_HOST']; // Defines the variable
and
$geturl = "domain";
does not?? What's the difference?

you can see the difference, starting with $_SERVER['HTTP_HOST']; instead of "domain";
 

ab.chess

New Member
Messages
9
Reaction score
0
Points
1
you mention the code is like 10 years old.
php support changes a lot. thats why you see different versions to run websites. like php 7.4 or php 8.0 etc
so whats written for php 6.0 will not always work in php 8.0 for example. depending on the code used.
some simple yet small scripts may still work but more complex ones do not.

php files need to have the .php extension to work properly. especially with configuration files.

$geturl = $_SERVER['HTTP_HOST']; // Defines the variable
and
$geturl = "domain";
does not?? What's the difference?

you can see the difference, starting with $_SERVER['HTTP_HOST']; instead of "domain";
Apparently you ignore the context. My question about the difference was "why the 1st stmt defines the variable and the 2nd is not".
As I can see after changing my code extension, both statements define the variable.
 

ctyrd

Active Member
Messages
868
Reaction score
78
Points
28
Apparently you ignore the context. My question about the difference was "why the 1st stmt defines the variable and the 2nd is not".
As I can see after changing my code extension, both statements define the variable.

Code:
<?php $geturl = "domain"; ?>
defines the variable to the word "domain".
Code:
<?php $geturl = $_SERVER['HTTP_HOST']; ?>
defines the variable to the host domain name (eg. chesspad.elementfx.com).
What are you starting over?? Your sites going 403. http://chesspad.elementfx.com/
 

ab.chess

New Member
Messages
9
Reaction score
0
Points
1
at the moment i have all my questions cleared. my small program is up and running.
i want to thank everyone who helped me.
 
Top