Reputation: 566
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;
}
?>
Upvotes: 0
Views: 48
Reputation: 3170
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;
}
Upvotes: 0
Reputation: 2192
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 ...
Upvotes: 1