I believe I am setting the if(strpos()); correctly. I've tried setting in a else{}; and elseif {}; after seeing it in a few examples, but they prompted for unexpected '}' and so forth.

<?php

$extension = '.com';

$lines = file('testdomains.txt');

foreach($lines as $line)
{
  // Check if the line contains the string we're looking for, and print if it does
  if(strpos($line, $extension) !== false)
    $line = preg_replace('/12:00:00 AM,AUC\b/','<br />', $line);
    $line = preg_replace('/,9\/28\/2013/', '', $line);
    echo $line;
}

?>
有帮助吗?

解决方案

this code

if(strpos($line, $extension) !== false)
$line = preg_replace('/12:00:00 AM,AUC\b/','<br />', $line);
$line = preg_replace('/,9\/28\/2013/', '', $line);
echo $line;

should be

if(strpos($line, $extension) !== false) {
   $line = preg_replace('/12:00:00 AM,AUC\b/','<br />', $line);
   $line = preg_replace('/,9\/28\/2013/', '', $line);
   echo $line;
}

you forgot to wrapper them ...

其他提示

When using if statements without the curly braces, remember than only one statement will be executed as part of that condition. If you want to place multiple statements you must use curly braces, and not just put them on the same line.

Your code should be like this

if(strpos($line, $extension) !== false){
    $line = preg_replace('/12:00:00 AM,AUC\b/','<br />', $line);
    $line = preg_replace('/,9\/28\/2013/', '', $line);
    echo $line;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top