开发者

PHP error with :,

开发者 https://www.devze.com 2023-04-09 20:40 出处:网络
I am trying to run this php code as a command line in applescript. here is the code \"/usr/bin/php -r \'($mac = \'gg:a2:gg:gg:gg:e6\'; $porttemp =\'9\'; $ip =\'255.255.255.255\';

I am trying to run this php code as a command line in applescript. here is the code

"/usr/bin/php -r '($mac = 'gg:a2:gg:gg:gg:e6'; $porttemp =  '9'; $ip ='255.255.255.255';  
$mac_bytes = explode(\":\", $mac);
$mac_addr = \"\"; 
for ($i=0; $i<6; $i++) 
$mac_addr .= chr(hexdec($mac_bytes[$i]));
$packet = \"\"; 
for ($i=0; $i<6; $i++)  /*6x 0xFF*/ 
$packet .= chr(255); 
for ($i=0; $i<16; $i++) /*16x MAC address*/ 
$packet .= $mac_addr;
$port = $porttemp;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); 
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, TRUE);
socket_sendto($sock, $packet, strlen($packet), 0, $ip, $port);开发者_Python百科 
socket_close($sock);
)'"

The syntax checks out fine on the applescript editor and the script runs but it pops this error:

Result: error "PHP Parse error: syntax error, unexpected ':' in Command line code on line 1" number 254

not sure what the issue is but is it the : in the mac address in the first line or the : later and also, I tried \":\" with the :`s but that did not work either. Any idea whats wrong?


Try something like this instead:

"/usr/bin/php -r '($mac = "gg:a2:gg:gg:gg:e6";
$porttemp =  "9";
$ip ="255.255.255.255";
$mac_bytes = explode(":", $mac);
$mac_addr = ""; 
for ($i=0; $i<6; $i++) 
$mac_addr .= chr(hexdec($mac_bytes[$i]));
$packet = ""; 
for ($i=0; $i<6; $i++)  /*6x 0xFF*/ 
$packet .= chr(255); 
for ($i=0; $i<16; $i++) /*16x MAC address*/ 
$packet .= $mac_addr;
$port = $porttemp;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); 
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, TRUE);
socket_sendto($sock, $packet, strlen($packet), 0, $ip, $port); 
socket_close($sock);
)'"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号