Code: Select all
#!/usr/bin/php
<?php
$sui = DEATH_SUICIDE
IF ($sui = DEATH_SUICIDE){
"SPAWN_ZONE death 10 10 4 1 5 5 true 15 15 2 3"
}
php?>
How's it look? I have no experience in php, but i'm trying to learn it.
Code: Select all
#!/usr/bin/php
<?php
$sui = DEATH_SUICIDE
IF ($sui = DEATH_SUICIDE){
"SPAWN_ZONE death 10 10 4 1 5 5 true 15 15 2 3"
}
php?>
Code: Select all
#!usr/bin/php
<?php
while (true)
{
//read the input
$line = rtrim(fgets(STDIN, 1024));
//check if line starts with DEATH_SUICIDE
if(preg_match("/^DEATH_SUICIDE/",$line)) {
//it does, so spawn a zone
echo "SPAWN_ZONE death 10 10 4 1 5 5 true 15 15 2 3\n"; // don't forget the \n at the end of every line!
}
//sleep one second and continue reading
sleep(1000);
}
?>
A few issues with your code: (1) fgets is a blocking call, so the sleep at the end of the loop is unnecessary. (2) You aren't checking for EOF (the script will never terminate if killed by KILL_SCRIPT). (3) Not really an issue, but the length parameter for fgets is optional. Here's a corrected version:AI-team wrote:here's what I guess you wanted to do, written in proper PHP […]
Code: Select all
#!usr/bin/php
<?php
while (true)
{
//read the input
$line = rtrim(fgets(STDIN));
if (feof(STDIN))
break;
//check if line starts with DEATH_SUICIDE
if(preg_match("/^DEATH_SUICIDE/",$line)) {
//it does, so spawn a zone
echo "SPAWN_ZONE death 10 10 4 1 5 5 true 15 15 2 3\n"; // don't forget the \n at the end of every line!
}
}
?>