【发布时间】:2015-10-06 12:25:47
【问题描述】:
如果文本以http://vk.com 开头,则添加
<iframe src="
最后
最后是" width="100%" height="450px" allowfullscreen=""></iframe>
所有http://vk.com/random$$ 都在数据库中。
并且链接总是随机的..
例子:
http://vk.com/video_ext.php?oid=187139107&id=163792624&hash=15cbcf3a3c503bd8
到
<iframe src="http://vk.com/video_ext.php?oid=187139107&id=163792624&hash=15cbcf3a3c503bd8" width="100%" height="450px" allowfullscreen=""></iframe>
请记住,在“video_ext.php?”之后它总是随机的。
所以.. 这是可以解决这个问题的脚本:
<?php
$mysqli = new mysqli("localhost", "admin_user", "yarak", "admin_name");
if ($mysqli->connect_errno)
{
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
}
if( $res = $mysqli->query("SELECT * FROM parts") )
{
$i = 0;
$done = array();
while( $row = $res->fetch_assoc() )
{
$link = unserialize( $row['part_content'] );
$link = $link[0];
if( preg_match( '#http://vk\.com/video_ext\.php\?oid=(.*?)#', $link ) )
{
$i = $i+1;
echo 'Original Link: ' . htmlentities( $link );
$link = preg_replace( '#http://vk\.com/video_ext\.php\?oid=(.*?)#', '<iframe src="http://vk.com/video_ext.php?oid=$1" width="100%" height="450px" allowfullscreen=""></iframe>', $link );
$_link = serialize( array( $link ) );
echo '<br />Part ID: ' . $row['part_id'] . '<br />New Link: '. htmlentities( $link ) . '<br /><br />';
if( $row['part_id'] AND !in_array( $row['part_id'], $done ) )
{
$done[] = $row['part_id'];
$mysqli->query( 'UPDATE `parts` SET `part_content` = \''.$_link.'\' WHERE `part_id`=\''.$row['part_id'].'\'' );
}
}
}
echo '<br />Count: ' . $i . '<br />Link conversion Completed.';
}
else
{
echo 'failed';
}
?>
这是我得到的:
Original Link: <iframe src="http://vk.com/video_ext.php?oid=THEIMPORTANTPART" width="100%" height="450px" allowfullscreen=""></iframe>
Part ID: 13489
New Link: <iframe src="<iframe src="http://vk.com/video_ext.php?oid=" width="100%" height="450px" allowfullscreen=""></iframe>THEIMPORTANTPART" width="100%" height="450px" allowfullscreen=""></iframe>
不知道是什么问题-.-
【问题讨论】:
-
基本调试:
var_dump($link)看看它是否包含您认为应该包含的内容。如果 preg_match 失败,则什么都不会发生... -
我发誓我今天早些时候看到了这个问题。
-
在哪里?也许同样的问题:)
标签: javascript php html database iframe