Pergunta

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;
}

?>
Foi útil?

Solução

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 ...

Outras dicas

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;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top