array buildin trouble

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

array buildin trouble

Post 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
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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.
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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?
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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?
Post Reply