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
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Fri Jul 18, 2003 10:48 am
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
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Fri Jul 18, 2003 11:43 am
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.
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Fri Jul 18, 2003 12:05 pm
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?
mesz
Forum Contributor
Posts: 216 Joined: Fri May 23, 2003 8:11 am
Location: M/cr
Post
by mesz » Fri Jul 18, 2003 1:54 pm
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 ?