将文本添加到随机字符串

时间:2015-07-16 21:17:43

标签: javascript php html database iframe

如果文字以var searchresults = document.getElementById('searchresults'); searchresults.addEventListener("click", function (event) { console.log(event.target, this); event.preventDefault(); if(event.target.tagName == 'IMG'){ imageing(event.target); } }); function imageing(targetImg) { var imageresult = document.getElementsByClassName('gs-image-box'); var xu = document.getElementById('companylogo'); var imgsrc = targetImg.src; xu.src = imgsrc; } 开头,则添加

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

请记住,&#34; video_ext.php?&#34;它总是随机的。

所以......这是可以处理的脚本:

<iframe src="http://vk.com/video_ext.php?oid=187139107&id=163792624&hash=15cbcf3a3c503bd8" width="100%" height="450px" allowfullscreen=""></iframe>

这是我得到的:

        <?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';
}
?>

我不知道问题是什么-.-

2 个答案:

答案 0 :(得分: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';
}

答案 1 :(得分:0)

你的preg_match模式需要转义正则表达式特殊字符。该模式应如下所示:

preg_match( '#http://vk\.com/video_ext\.php\?oid=(.*?)#', $link )

在preg_replace中类似。