有一点编码问题,如何检查$ row ['value']的值是否包含某些字符,在这种情况下,如果'rename_file'包含一个'128'的文件名它。我有这个,但它似乎没有回应它。
$row = mysql_fetch_assoc($result);
{
while ($row = mysql_fetch_assoc($result))
{
echo $row['c_ID'] . " " . $row['source_file'] . " " . $row['rename_file'] ." " . $row['p_ID'];
if ($row['rename_file'] = '%128%') {
echo "<p> This is a 128";
} else
echo "<br>";
}
}
非常感谢。 CP
答案 0 :(得分:1)
使用preg_match()
:
if(preg_match('/128/',$row['rename_file'])){
echo "<p> This is a 128";
} else {
echo "<br>";
}
或strpos()
:
if(strpos($row['rename_file'], '128') !== false){
echo "<p> This is a 128";
} else {
echo "<br>";
}
答案 1 :(得分:0)
查看stristr搜索关键字。 http://php.net/manual/en/function.stristr.php
答案 2 :(得分:0)
if (strpos($row['rename_file'], '128') !== false) {
echo "<p> This is a 128";
}
答案 3 :(得分:0)
如果你想检查128行中的每个值:
function searchArray($search, $array)
{
foreach($array as $key => $value)
{
if (stristr($value, $search))
{
return true;
}
}
return false;
}
$row = array('c_ID'=>'Prefix_128_ABC','source_file'=>'EFG.xml','rename_file'=>'FOO.xml');
if (searchArray('128',$row) !== false) {
echo "<p> This is a 128";
}else{
echo "<p> This is not a 128";
}
略有修改: http://forums.phpfreaks.com/topic/195499-partial-text-match-in-array/
- OOPS!误解。好吧,如果你需要的话,这就是你要做的... -