我是 php 新手,正在做练习。
我写echo在一个函数中,但没有任何反应,没有结果。
class Glass {
public function height($h) {
return $h;
echo "The height is: empty $h" . "<br>";
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试echo在函数之外时,我得到一个结果:
echo "The base circle area is : $a";
Run Code Online (Sandbox Code Playgroud)
这里有什么问题?
我正在尝试完成一个简单的回显服务器。目标是将消息重复返回给客户端。服务器和客户端都编译。服务器绑定到本地主机和端口 8080。客户端有地址、端口和消息。当客户端将程序执行到 sendto 部分时,它会在那里停下来等待。我的目标是将其发送到服务器,然后服务器将其发回。
问题:客户端正在发送消息,服务器可以正确接收消息,但服务器无法返回消息。请帮忙!
服务器端代码:
#include <iostream>
#include <string.h>
#include <fstream>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#define PORT 8080
using namespace std;
int main() {
int serSockDes, len, readStatus;
struct sockaddr_in serAddr, cliAddr;
char buff[1024] = {0};
char msg[] = "Hello to you too!!!\n";
//creating a new server socket
if((serSockDes = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("socket creation error...\n");
exit(-1);
}
//binding the port to ip and port
serAddr.sin_family = AF_INET;
serAddr.sin_port = htons(PORT);
serAddr.sin_addr.s_addr …Run Code Online (Sandbox Code Playgroud) 我有一个将数据插入 MySQL 的代码,该代码运行良好,我想将当前的 java 脚本警报替换为 sweetalert2。我浏览了所有论坛但找不到任何东西。谁能帮我?谢谢。
<?php
//session_start();
//include "dbcon.php";
error_reporting(0);
$conn = new PDO('mysql:host=localhost; dbname=fleet','root', 'root');
$department=$_POST['department'];
$employee=$_POST['employee'];
$approver=$_POST['approver'];
$depart_date=$_POST['depart_date'];
$return_date=$_POST['return_date'];
$depart_time=$_POST['depart_time'];
$return_time=$_POST['return_time'];
$depart_place=$_POST['depart_place'];
$arrival_place=$_POST['arrival_place'];
$reason=$_POST['reason'];
$request_timestamp=$_POST['request_timestamp'];
$approver_email = $_POST['approver_email'];
//employee_name = $_POST['employee_name'];
$employee_name = $_POST['employee_name'];
$approver_name = $_POST['approver_name'];
$employee_title = $_POST['employee_title'];
//$no_of_passengers = '';
//$name_of_passengers = '';
$no_of_passengers = $_POST['no_of_passengers'];
$name_of_passengers = $_POST['name_of_passengers'];
//$no_of_passengers2 = $_POST['no_of_passengers2'];
//$name_of_passengers2 = $_POST['name_of_passengers2'];
//$no_of_passengers2 = '';
//$name_of_passengers2 = '';
$sql2='';
//include "mail.php";
// $no_of_passengers2 = $_POST['no_of_passengers2'];
// $name_of_passengers2 = $_POST['name_of_passengers2'];
if (isset($_POST['submit'])) …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 exec 系列函数运行命令行参数(特别是 echo)。如果我编写自己的可执行文件并运行它,我可以运行 execv 函数,但是如果我尝试运行 touch 或 echo 它会返回 -1
#include <stdio.h>
#include <unistd.h> // exec functions
#include <sys/types.h> // pid_t
#include <sys/wait.h>
#define HIGH 1
#define LOW 0
int digitalWrite(int pin, short type) {
pid_t pid = fork();
if (pid == 0) {
printf("pid == %i\n", pid);
if (type == HIGH) {
char* args[] = {"echo", "1", ">", "/sys/class/gpio/gpio67/value", NULL};
int val = execv(args[0], args);
printf("ran function execl, %i\n", val);
} else {
printf("Unable to do anything but …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试开发一个使用套接字连接到 laravel 服务器的 flutter 应用程序。
我正在遵循一个教程,其中他使用https://github.com/beyondcode/laravel-websockets并连接到 Pusher,然后从我的移动应用程序中使用 Echo 和 Pusher Client。
老实说,我在这个过程中迷失了方向,无法真正说出每个的目的是什么。
如果有人能帮助解释 Pusher、Websockets 和 Echo 之间的区别,我将非常感激。
谢谢你!
$text . = '1 paragraph';
$text . = '2 paragraph';
$text . = '3 paragraph';
echo $text;
Run Code Online (Sandbox Code Playgroud)
此代码给出错误syntax error, unexpected '='.
问题是什么?
我的代码有问题.我很确定它与报价有关.让我来证明一下.
这很好用:
<?php if ( $is_latest_post ) echo '
hello world
'; ?>
Run Code Online (Sandbox Code Playgroud)
这不起作用:
<?php if ( $is_latest_post ) echo '
<a class="recent<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>" href="<?php bloginfo('url'); ?>/<?php echo $category[0]->category_nicename; ?>"><?php echo $category[0]->cat_name; ?></a>
'; ?>
Run Code Online (Sandbox Code Playgroud)
为什么不起作用?我可以改变什么才能使它发挥作用?a class代码的一部分完全在if ( $is_latest_post )语句之外.感谢我刚开始用PHP学习编码.
我有一个值数组,我试图使用以下代码输出到字符串:
$arrayINS = explode(", ", $arraystring);
foreach ($arrayINS as &$array1INS) {
$array1INS = "(" . $arrayINS . ", 'Some Text Here')";
}
$arrayvaluesINS = implode(', ', $arrayINS);
Run Code Online (Sandbox Code Playgroud)
现在,让我们说吧$arraystring = 25145, 25064, 24812.我希望echo $arrayvaluesINS如此
(25145,'有些文字在这里'),(25064,'有些文字在这里'),(24812,'有些文字在这里')
但相反,我得到的是:
(数组,'这里有些文字'),(数组,'这里有些文字'),(数组,'这里有些文字')
我究竟做错了什么?
我有一个看起来像这样的字符串:
<center>
<div style="margin-top: 10px; margin-bottom: 10px; font-size: 20px; color: #000; font-weight: bold;">
<?php echo strlen(file_get_contents('test.txt')); ?> Applications Sent
</div>
</center>
Run Code Online (Sandbox Code Playgroud)
但是,我想用if语句来回应这个问题.例如:
if ($test == '') {
echo '<center><div style="margin-top: 10px; margin-bottom: 10px; font-size: 20px; color: #000; font-weight: bold;"><?php echo strlen(file_get_contents("test.txt")); ?> Applications Sent</div></center>';
}
Run Code Online (Sandbox Code Playgroud)
问题是这不起作用,因为原始字符串中已经有回声.我怎么能绕过这个?
我真的想通过操纵得到一些数字范围....
我的代码目前工作正常,但输出是我遇到的问题.
我想回应一些像00/00,00/01等的东西
但是我的代码给了我0/0,0/1,0/2等
我怎么去这个?
这是我的代码
<?php
foreach (range(00, 99) as $no2) {
foreach (range(00, 99) as $no3) {
echo $no2 . "/" . "$no3</br>";
}
}
?>
Run Code Online (Sandbox Code Playgroud) echo ×10
php ×7
function ×2
string ×2
arrays ×1
c ×1
c++ ×1
client ×1
exec ×1
integer ×1
javascript ×1
laravel ×1
laravel-echo ×1
numbers ×1
pusher ×1
server ×1
sweetalert ×1
sweetalert2 ×1
syntax-error ×1
udp ×1
websocket ×1