Php 使星号之间的文本加粗
我想在聊天中调用正则表达式,在单个星号之间生成文本粗体 类似于:测试!*您好,这是一个PHP脚本* 谁能帮我?我已经在聊天室发布了一些PHP脚本的过程,但是正则表达式没有出现 (*)+([^.*?$]+)+(*)是我为此假设的正则表达式。我已经包括了你“发送”到聊天室的部分,添加到聊天室并显示 我做错了什么?我坐了好几个小时想弄明白这件事。谢谢Php 使星号之间的文本加粗,php,json,ajax,Php,Json,Ajax,我想在聊天中调用正则表达式,在单个星号之间生成文本粗体 类似于:测试!*您好,这是一个PHP脚本* 谁能帮我?我已经在聊天室发布了一些PHP脚本的过程,但是正则表达式没有出现 (*)+([^.*?$]+)+(*)是我为此假设的正则表达式。我已经包括了你“发送”到聊天室的部分,添加到聊天室并显示 我做错了什么?我坐了好几个小时想弄明白这件事。谢谢 case('send'): $message = htmlentities(strip_tags($_POST['message']))
case('send'):
$message = htmlentities(strip_tags($_POST['message']));
$nickname = htmlentities(strip_tags($_POST['username']));
$text = "/(\*)+([^.*?$]+)+(\*)";
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
$avc = htmlentities(strip_tags($_POST['avatarC']));
$rbc = htmlentities(strip_tags($_POST['robeC']));
$message = str_replace("\n", "", $message);
if(($message) != "")
{
$temp_msg = "";
if(strlen($message)>75)
{
$temp_msg = wordwrap($message, 75, "<br />");
}
else
{
$temp_msg = $message;
}
/*if(preg_match($reg_exUrl, $avc, $url)) {
$avc = preg_replace($reg_exUrl, '<a href="'.$url[0].'" target="_blank">'.$url[0].'</a>', $avc);
}
$avc = str_replace("\n", " ", $avc);*/
$current_date = date('H:i:s');
//fwrite(fopen($file, 'a'), "<div class=\"message_container message_cell\"><img class=\"img_message\" src=$avc></img><img class=\"img_message\" src=$rbc></img><span class=\"message_text\"><span class=\"message_user\">"<b>. $nickname ."</b> ".$current_date."</span>". $message ."</span></div><br />\n");
fwrite(fopen($file, 'a'), "<div class=\"message_container message_cell\"><img class=\"img_message\" src=$avc></img><img class=\"img_message\" src=$rbc></img><span class=\"message_text\"><span class=\"message_user\"><b>" . $nickname ."</b> [".$current_date."]:</span><br /><br/>". $temp_msg ."</span></div><br />\n");
}
break;
case('addToChat'):
$lines = file($file);
$fristCount = count($lines);
$nickname = $_POST['username'];
fwrite(fopen($file, 'a'), "<div class=\"message_cell message_container\">".$nickname."</div><div>\n");
$text = array();
$lines = file($file);
$log['file'] = $file;
foreach ($lines as $line_num => $line) {
$line = str_replace("\n", "", $line);
if($line != ""){
$text[] = $line;
}
}
case('send'):
$message=htmlentities(strip_标记($_POST['message']);
$昵称=htmlentities(带标签($\u POST['username']);
$text=“/(\*)+([^.*?$])+(\*)”;
$reg|u exUrl=“/(http | https | ftp | ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/”;
$avc=htmlentities(strip_标签($_POST['avatarC']);
$rbc=htmlentities(strip_标签($_POST['robeC']);
$message=str\u replace(“\n”,”,$message);
如果(($message)!=“”)
{
$temp_msg=“”;
如果(strlen($message)>75)
{
$temp_msg=wordwrap($message,75,“
”);
}
其他的
{
$temp_msg=$message;
}
/*if(预匹配($reg\U exUrl、$avc、$url)){
$avc=preg_replace($reg_exUrl,,$avc);
}
$avc=str_replace(“\n”,”,$avc)*/
$current_date=日期('H:i:s');
//fwrite(fopen($file,'a'),“”.$昵称.“$current\u date.“$message.”
\n”);
fwrite(fopen($file,'a'),“.$nickname.”[“$current\u date.”]:
“$temp\u msg.”
\n”);
}
打破
case('addToChat'):
$lines=文件($file);
$fristCount=计数($line);
$nickname=$_POST['username'];
fwrite(fopen($file,'a'),“.$昵称”。\n”);
$text=array();
$lines=文件($file);
$log['file']=$file;
foreach($line作为$line_num=>$line的行){
$line=str\u replace(“\n”,”,$line);
如果($line!=“”){
$text[]=$line;
}
}
如果您在聊天室中的消息将具有这种单一模式,那么下面的脚本将起作用:
<?php
$message="Test! * Hello This is a PHP script * and this another one";
$pattern = "/(?<=\*).+?(?=\*)/";
preg_match($pattern, $message,$matches);
$temp_msg=$message;
for($i=0;$i<count($matches);$i++){
$temp_msg=str_replace($matches[$i],"<b>".$matches[$i]."</b>",$message);
}
$temp_msg=str_replace("*","",$temp_msg);
echo $temp_msg;
?>
如果您在聊天室中的消息将具有这种单一模式,那么下面的脚本将起作用:
<?php
$message="Test! * Hello This is a PHP script * and this another one";
$pattern = "/(?<=\*).+?(?=\*)/";
preg_match($pattern, $message,$matches);
$temp_msg=$message;
for($i=0;$i<count($matches);$i++){
$temp_msg=str_replace($matches[$i],"<b>".$matches[$i]."</b>",$message);
}
$temp_msg=str_replace("*","",$temp_msg);
echo $temp_msg;
?>