Page 1 of 1

array buildin trouble

Posted: Fri Jul 18, 2003 10:48 am
by mesz
Avin trouble building an array - my first array attempt, not just laziness!

Code: Select all

<?PHP 
$data = file('news.dat'); 
$data = array_reverse($data); 
{ 
$string = "$data";
$pattern = "/\\[img\\](.+?)\\[\\/img\\]/, /\[URL=(.*?)\](.*)\[\/URL\]/i";
$replacement = "<img src="\\1">,<a class='link3' //href="http://\\1">\\2</a>";
print preg_replace($pattern, $replacement, $string);
} 
?>
Error:
Warning: Unexpected character in input: ''' (ASCII=92) state=1 in /home/.sites/14/site467/web/pstore/add.php on line 12

Warning: Unexpected character in input: ''' (ASCII=92) state=1 in /home/.sites/14/site467/web/pstore/add.php on line 12

Parse error: parse error, unexpected T_LNUMBER in /home/.sites/14/site467/web/pstore/add.php on line 12

Posted: Fri Jul 18, 2003 11:43 am
by mesz
I amended the script to include a changed delimiter:

Code: Select all

<?PHP 
$data = file('news.dat'); 
$data = array_reverse($data); 
{ 
$string = "$data";
$pattern = '!/\\[img\\](.+?)\\[\\/img\\]/!i, !/\[URL=(.*?)\](.*)\[\/URL\]/i';
$replacement = '!<img src="\\1">!i, !<a class="link3" 

//href="http://\\1">\\2</a>!i';
print preg_replace($pattern, $replacement, $string);
} 
?>
now I get this error:
Warning Unknown Modifier '.'
on line 13

Aaargh.

Posted: Fri Jul 18, 2003 12:05 pm
by mesz
OK, I took out the array_reverse function to give

Code: Select all

<?PHP 
$data = file('news.dat'); 
{ 
$string = "$data"; 
$pattern = '!/\\[img\\](.+?)\\[\\/img\\]/!i, !/\[URL=(.*?)\](.*)\[\/URL\]/i'; 
$replacement = '!<img src="\\1">!, !<a class="link3" //href="http://\\1">\\2</a>!'; 
print str_replace($pattern, $replacement, $string); 
} 
?>
Now all that prints to screen is
the word ' Array '
Why is this?

Posted: Fri Jul 18, 2003 1:54 pm
by mesz
My final bid for the day,
somebody please help! :(

Code: Select all

<?PHP 
$data = file('news.dat'); 
{ 
$arrayFiles = implode($data, $fin);
$string = "$data"; 
$pattern = '!/\\[img\\](.+?)\\[\\/img\\]/!i, !/\[URL=(.*?)\](.*)\[\/URL\]/i'; 
$replacement = '!<img src="\\1">!, !<a class="link3" //href="http://\\1">\\2</a>!'; 
$fin= str_replace($pattern, $replacement, $string);
print $arrayFiles;
} 
?>
all is printed to the screen, except the [img] and [ url ] str_replacement has not worked.
Does anybody know why?