0

関数で文字を変えてみます

 <?php
$string = "Hi everybody people [gal~images/articles~100~100~4]  here other imagen [gal~images/products~100~100~3]";

$regex = "/\[(.*?)\]/";
preg_match_all($regex, $string, $matches);

for($i=0; $i<count($matches[1]);$i++)
{
$match = $matches[1][$i];
$array = explode('~', $match);

//$newValuet="gal("".$array[1]."","".$array[2]."","".$array[3]."","".$array[4]."")";

$newValue="gal(".$array[1].",".$array[2].",".$array[3].",".$array[4].")";


$string = str_replace($matches[0][$i],$newValue,$string);

}

echo $string;
?>

ここでの問題:

$newValue="gal(".$array[1].",".$array[2].",".$array[3].",".$array[4].")";


    $string = str_replace($matches[0][$i],$newValue,$string);

関数は正しい結果を与えません。さまざまな方法を試しますが、問題を続けます。すべての関数が表示されますが、これが機能しません。答えられる場合は、このコードを変更してください。理解できるようにします。すべての助けに感謝します。

詳しくは

スクリプトは新しい値を生成します。この値は、insert および show replace tags と put all well 、show text および tags replace のために Gall の関数を送信する必要があります。

 $newValue="gal(".$array[1].",".$array[2].",".$array[3].",".$array[4].")";

 $string = str_replace($matches[0][$i],$newValue,$string);

ここで、関数は gal を表示します。関数は、str_replace に実行してテキストを配置する必要がある場合に実行されます。タグを置換して続行する前に、これだけが失敗します。

PD : 私 は 何 人 か の 人 に 敬意 を 払い ます . 私 は ここ に 質問 を 送り ます .学ぶか、助けが必要で、明日は他の人やこの人を助けることができます。

よろしく

4

2 に答える 2

0

ギャラリーの機能

  <?php
    function gal($dire,$w_size,$h_size,$cols)
    {
    $n_images=0;

    $dir=opendir("$dire");
    while($file=readdir($dir))
    {
    if ($file!="." && $file!=".." && $file!="Thumbs.db" && $file!="index.html" && $file!=".htaccess" && $file!="config.dat")
    {
    $n_images++;
    $imagenes[]=$file;
    }

    }
    closedir($dir);

    $num_img="".$n_images."";
    $num_img_cols="".$cols."";
    $num_filas="".ceil($num_img/$num_img_cols)."";

    echo '<table width="10%" border="0" cellpadding="3" cellspacing="2" align="center">
    <tr> 
    <td colspan="'.$num_img_cols.'">&nbsp;</td>
    </tr><tr>';

    $x=1;

    for ($j=0;$j<$n_images;$j++)
    {
    print "<td align='center'>";

    //echo '<img src="'.$dire.'/'.$imagenes[$j].'" width="'.$w_size.'" height="'.$h_size.'">';

    print "<a href='".$dire."/".$imagenes[$j]."' class='highslide' onclick=\"return hs.expand(this,{slideshowGroup:'group1',align:'center'})\">";
    print '<img src="indexer_resizer.php?ruta_f='.$dire.'/&image='.$imagenes[$j].'&new_width='.$w_size.'&new_height='.$h_size.'" border="0" alt="Pulse para Ampliar" title="Pulse para Ampliar">
    </a>';

    if ($x%$num_img_cols==0)
    {
    print "</tr>";
    }
    $x++;
    }

    echo "</table>";
    }
    ?>

**Function for replace tags**

     <?php
    $string = "Hola todos os presento una nueva galeria  [galt~imagenes/articulos~100~100~4]  Aqui otra más [gal~imagenes/productos~100~100~3]";

    $regex = "/\[(.*?)\]/";
    preg_match_all($regex, $string, $matches);

    for($i=0; $i<count($matches[1]);$i++)
    {
    $match = $matches[1][$i];
    $array = explode('~', $match);

    //$newValuet="gal("".$array[1]."","".$array[2]."","".$array[3]."","".$array[4]."")";

    $newValue="gal(".$array[1].",".$array[2].",".$array[3].",".$array[4].")";


    $string = str_replace($matches[0][$i],$newValue,$string);

    }

    echo $string;
    ?> 

これはすべての機能であり、ここで確認できます。スクリプトは、ギャラリーを表示するための機能と、ギャラリーを置き換えて表示するためのスクリプトの2つを使用しますが、うまく機能しません

スクリプトは新しい値を生成します。この値は、insert および show replace tags と put all well 、show text および tags replace のために Gall の関数を送信する必要があります。

 $newValue="gal(".$array[1].",".$array[2].",".$array[3].",".$array[4].")";

 $string = str_replace($matches[0][$i],$newValue,$string);

ここで、関数は gal を表示します。関数は、str_replace に実行してテキストを配置する必要がある場合に実行されます。タグを置換して続行する前に、これだけが失敗します。

PD : 私 は 何 人 か の 人 に 敬意 を 払っ て い ます . 私 は ここ に 質問 を 送り ます .学ぶか、助けが必要で、明日は他の人やこの人を助けることができます。

よろしく

于 2012-11-28T19:49:20.560 に答える
0

文字列のこれらの部分をキャプチャするには、次を試してください。

$string = "Hi everybody people [gal~images/articles~100~100~4]  here other imagen [gal~images/products~100~100~3]";

preg_match_all('/\[(.+)\]/ismU, $string, $matches);

また

preg_match_all('/\[(\w+)\~([a-z0-9\/]+)\~(\d+)\~(\d+)\~(\d+)\]/ismU, $string, $matches);

最後のものは、もう少し複雑な構造に$matchesなりますが、必要なデータを正確に取得できることを証明しています。

于 2012-11-28T20:55:03.880 に答える