English 中文(简体)
定期表达(前称呼全)和阵列
原标题:Regular Expression (preg_match_all) and array

该法令是:

   <?php
    $matchWith = "# http://videosite.com/id1 http://videosite.com/id2 # # http://videosite.com/id3 http://videosite.com/id4 #";

    preg_match_all( %(#)shttp://videosite.com/(w+)
{0,1}shttp://videosite.com/(w+)
{0,1}s(#)% , $matchWith, $result);
    foreach($result[2] as $value)
    {  
    print  <a href="http://videosite.com/ .$value. ">
    First Part
    </a> ;        

    }  
    foreach($result[3] as $value)
    {  
    print  <a href="http://videosite.com/ .$value. ">
    Second Part
    </a> ;        
    }
    ?>

问题:

我愿表示:第一部分、第二部分和第二部分。

但它表明了这一点: 第一编,第一部分,第二部分,第二部分。

I really hope you understand. Thanks

最佳回答
   <?php
    $matchWith = "# http://videosite.com/id1 http://videosite.com/id2 # # http://videosite.com/id3 http://videosite.com/id4 #";

    preg_match_all( %(#)shttp://videosite.com/(w+)
{0,1}shttp://videosite.com/(w+)
{0,1}s(#)% , $matchWith, $result);
    for($i = 0; $i < count($result[2]); $i++){
       print  <a href="http://videosite.com/ .$result[2][$i]. ">
       First Part
       </a> ;
       print  <a href="http://videosite.com/ .$result[3][$i]. ">
       Second Part
       </a> ;     
    }
    ?>

答复认为,这两个阵列有一个平行的结构。

EDIT:将i=i++改为i++

问题回答

Is this what you want?

for($i = 0; $i < count($result); $i++)
{  
    print  <a href="http://videosite.com/ .$result[$1][2]. ">
    First Part
    </a> ;        

    print  <a href="http://videosite.com/ .$result[$1][3]. ">
    Second Part
    </a> ; 
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签