Domanda

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

?>
È stato utile?

Soluzione

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

Altri suggerimenti

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;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top