|  | |  |
02-12-2005, 01:18 PM
|
#1 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,530
| scripting with php: new line i'm making a shell script with php. example: Code: #!/usr/local/bin/php
<?
echo "hello\n";
echo "world\n";
?> it actually prints out the new line characters instead of going to a new line. is there a way to get it to go to the next line with php?
__________________ Mike |
| |
02-12-2005, 01:19 PM
|
#2 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,530
| nevermind, i was using single quotes in my code .. double quotes works fine.
__________________ Mike |
| |
02-12-2005, 07:15 PM
|
#3 (permalink)
| | Centurion Nova Prime
Join Date: May 2002 Location: Oak Park, IL (USA)
Posts: 287
| Hey, sde.
I was just curious what prompted this. It never occurred to me to use PHP for shell scripting. With the easy database connectivity and other cool features, it could be a good replacement for a lot of Perl stuff.
__________________ It takes 2 points to draw a straight line, but at least 3 points to draw a conclusion. |
| |
02-12-2005, 08:41 PM
|
#4 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,530
| i've been using php more and more lately for shell scripting. as you mentioned, database connectivity is the #1 reason, not to mention it's my favorite language.
a while back i'd mainly use it for fun integration with our half-life game servers i help run, but now i use php scripting for clients too. one of them needs several datafeeds generated from their huge product list everyday and php is perfect for that.
__________________ Mike |
| |
02-13-2005, 10:47 AM
|
#5 (permalink)
| | Senior Grasshopper
Join Date: Jun 2003 Location: FL
Posts: 317
|  string interpolation.. Bites me from time to time as well..
I mainly stick to perl for shell script-related tasks, but it certainly makes things easier when you have a chunk of PHP already written that you can use via cron/etc.. |
| |
02-15-2005, 08:41 PM
|
#6 (permalink)
| | Regular Contributor
Join Date: Feb 2003 Location: indisclosed
Posts: 210
| You can also use C for shell scripting..... |
| |
02-15-2005, 09:01 PM
|
#7 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,530
| really? i didn't know C could be used as a scripting language.
the only drawback of php scripting that i've come across is that it has no user input feature. ( i think ) .. now that would be cool.
__________________ Mike |
| |
02-15-2005, 09:15 PM
|
#8 (permalink)
| | Centurion Nova Prime
Join Date: May 2002 Location: Oak Park, IL (USA)
Posts: 287
| sde, it occurred to me that you only have to intercept stdin to add user input functionality. I found this in a quick search: Code: <?php
function read($len = 255) {
$fp=fopen('php://stdin', 'r');
$input=fgets($fp, $len);
fclose($fp);
return str_replace(array("\r", "\n"), array('', ''), $input);
}
echo("Whats your name? ");
$name = read();
echo("Hello $name!\n");
?> The original link is: PHP User Input Example
It's supposed to be cross platform.
__________________ It takes 2 points to draw a straight line, but at least 3 points to draw a conclusion. |
| |
02-15-2005, 09:18 PM
|
#9 (permalink)
| | Moderator
Join Date: May 2002 Location: us.ca
Posts: 4,530
| oh damn, that is cool  thanks !
__________________ Mike |
| |
02-16-2005, 06:04 PM
|
#10 (permalink)
| | Senior Grasshopper
Join Date: Jun 2003 Location: FL
Posts: 317
| Quote: |
Originally Posted by Kernel_Killer You can also use C for shell scripting..... | Depends on your definition I suppose.. (and willingness to learn C)
sde: PHP's readline support might handy as well.
-r |
| | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -8. The time now is 12:22 AM. |
Copyright © 2000-2008, Milano Interactive Web Hosting provided by Portal 360 Web Hosting |  | |