开发者

PHP: string got a substring, show that string

开发者 https://www.devze.com 2023-03-07 14:33 出处:网络
I get a whole list of arrays with different strings, and I want that the strings which contain \"_pmx\" be put in my dropdown list.

I get a whole list of arrays with different strings, and I want that the strings which contain "_pmx" be put in my dropdown list.

    $buff = ftp_nlist($conn_id,"BackupFiles");
        echo "<select id='pmxbestand' name='pmxbestand'>";
        foreach($buff as $i=>$value) {
                $resultaat = strstr($value, '_pmx');
                echo "<option value='".$resultaat."'>".$resultaat."</option>";
        }
        echo "</select>";

I thought this would do the trick, but i开发者_如何学Ct turns out it doesn't, can anyone help me?


Try substr_count:

$buff = ftp_nlist($conn_id,"BackupFiles");
echo "<select id='pmxbestand' name='pmxbestand'>";
foreach($buff as $i=>$value) {
        if (substr_count($value, '_pmx') > 0) echo "<option value='".$value."'>".$value."</option>";
}
echo "</select>";


I get a whole list of arrays with different strings, and I want that the strings which contain "_pmx" be put in my dropdown list.

How about:

foreach( $buff as $i => $value ) {
      if( ( $result = strstr( $value, '_pmx' ) ) !== false ) {
          printf( '<option value="%1$s">%1$s</option>', $result );
      }
}

EDIT: Had a syntax error.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号