问题描述
如果文字以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>
我不知道问题是什么-.-
1楼
这是您要的吗?
$mysqli = new mysqli("localhost", "admin_e1", "sure", "admin_main");
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 (strpos($text, 'http://vk.com') === 0)
{
$i = $i+1;
echo 'Original Link: ' . htmlentities( $link );
$link = '<iframe src="' . $link . '" width="100%" height="450px" allowfullscreen=""></iframe>';
$_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';
}
2楼
您的preg_match模式需要转义正则表达式特殊字符。 该模式应如下所示:
preg_match( '#http://vk\.com/video_ext\.php\?oid=(.*?)#', $link )
与preg_replace类似。