Php 嵌入的youtube视频正在从聊天中删除我的信息
当我试图在回复或发送消息时激活嵌入的youtube视频时,我的php脚本中出现了一些问题 我的php脚本是:Php 嵌入的youtube视频正在从聊天中删除我的信息,php,mysqli,youtube,Php,Mysqli,Youtube,当我试图在回复或发送消息时激活嵌入的youtube视频时,我的php脚本中出现了一些问题 我的php脚本是: <?php if($_GET['u'] != $user) { $messages = addslashes($_POST['message']); $messages = preg_replace_callback('#(?:https?://\S+)|(?:www.\S+)|(?
<?php
if($_GET['u'] != $user) {
$messages = addslashes($_POST['message']);
$messages = preg_replace_callback('#(?:https?://\S+)|(?:www.\S+)|(?:\S+\.\S+)#', function($arr)
{
if(strpos($arr[0], 'http') !== 0)
{
$arr[0] = 'http://' . $arr[0];
}
$url = parse_url($arr[0]);
// images
if(preg_match('#\.(png|jpg|gif)$#', $url['path']))
{
echo '<img src="'. $arr[0] . '" />';
}
// youtube
if(in_array($url['host'], array('www.youtube.com', 'youtube.com'))
&& $url['path'] == '/watch'
&& isset($url['query']))
{
parse_str($url['query'], $query);
return sprintf('<iframe width="560" height="315" src="http://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>', $query['v']);
}
//links
return nl2br(sprintf('<a href="%1$s">%1$s </a> ', $arr[0]));
}, $messages);
$to = $_GET['u'];
$selPictureMsg = "SELECT * FROM users WHERE username = '$user'";
$result = mysqli_query($sql, $selPictureMsg);
$msgPicRow = mysqli_fetch_assoc($result);
$selPictureMsg11 = "SELECT * FROM users WHERE username = '$to'";
$result11 = mysqli_query($sql, $selPictureMsg11);
$msgPicRow11 = mysqli_fetch_assoc($result11);
$user_pic = $msgPicRow['profile'];
$receiver_pic = $msgPicRow11['profile'];
if(isset($_POST['msgSend'])) {
if(strlen($messages) <= 1) {
echo "<div class='error'>Sorry! Your message is too small. It needs to be more than 1 character.</div>";
} else {
$insMsg = "INSERT INTO messages VALUES('','$user','$to','$messages','0','$user_pic','$receiver_pic', NOW())";
$sql->query($insMsg);
echo "<div class='success'>Your message has been sent to ".$to." successfully.</div><br />";
}
}
$selmsg1 = "SELECT * FROM messages WHERE (to_user='$user' AND from_user='$to') OR (to_user ='$to' AND from_user='$user') ORDER BY date DESC";
$resultmsg1 = $sql->query($selmsg1);
$rownum = mysqli_num_rows($resultmsg1);
if($rownum > 0) {
$i = '';
echo "<table>
<tr class='chat'>";
while($assocMsg = mysqli_fetch_assoc($resultmsg1)) {
if($user == $_GET['from'] || $user != $assocMsg['to_user']) {
$smilies = array(
':|' => 'bored',
':-|' => 'bored',
':-o' => 'scared',
':-O' => 'scared',
':o' => 'scared',
':O' => 'scared',
';)' => 'wink',
';-)' => 'wink',
':p' => 'tongue',
':-p' => 'tongue',
':P' => 'tongue',
':-P' => 'tongue',
':D' => 'happy',
':-D' => 'happy',
';P' => 'wink-tongue',
';-P' => 'wink-tongue',
':)' => 'smile',
':-)' => 'smile',
':(' => 'sad',
':-(' => 'sad',
'<3' => 'heart',
':*' => 'kiss',
'*_*' => 'in-love',
';(' => 'crying',
':a' => 'angry',
':@' => 'rage',
':3' => 'normal-kiss',
'><' => 'shy',
';D' => 'happily',
';-D' => 'happily',
':$' => 'blushing',
'o_o"' => 'dont-get',
'XD' => 'laugh',
'*lookdown*' => 'look-down',
'*lookup*' => 'look-up',
'*lookleft*' => 'look-left',
'*lookright*' => 'look-right',
'$_$' => 'money',
'$.$' => 'money',
'@_@' => 'nerd',
'@.@' => 'nerd',
'*vomit*' => 'vomit'
);
$replace = array();
foreach ($smilies as $smiley => $imgName)
{
array_push($replace, '<img src="images/emoticons/'.$imgName.'.png" alt="'.$smiley.'" />');
}
$assocMsg["message"] = str_replace(array_keys($smilies), $replace, $assocMsg["message"]);
echo "
<div style='width:100%; max-height: 300px; overflow: auto;'>
<td><a href='profile.php?u=".$assocMsg['from_user']."'><img src='".$assocMsg['user_picture']."' width='auto' height='70px' /></a></td>
<td>".$assocMsg['message']."<br />".$video."</td>
</tr>
<tr>
<td colspan='5'><i>".$assocMsg['date']."</i></td>
</div>
";
$i++;
if($i % 1 == 0) {
echo "</tr><tr class='chat'>";
}
} else {
echo "
<div style='width:100%; max-height: 300px; overflow: auto;'>
<td><a href='profile.php?u=".$assocMsg['to_user']."<img src='".$assocMsg['friend_picture']."' width='auto' height='70px' /></a></td>
<td>".$messages."</td>
</tr>
<tr>
<td colspan='5'><i>".$assocMsg['date']."</i></td>
</div>
";
$i++;
if($i % 1 == 0) {
echo "</tr><tr class='chat'>";
}
}
}
echo "</tr>
</table><hr />";
} else {
echo "You don't have any conversations with $to<br /><hr />";
}
?>