문제

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