Page 1 of 1

news script - link include

Posted: Fri Nov 21, 2003 10:03 am
by mesz
I have this mashed together script for a quick news include feature.
yet the links dont work and teh images dont display.
Does anybody know why?

Code: Select all

<?php
<?
$data = file('./news2/news.txt'); 
$data = array_reverse($data);
foreach($data as $element) {
    $ele = trim($ele);
$string = $pieces[3]; 
$pattern = array('!\[img\](.+?)\[/img\]!i', '!\[URL=(.*?)\](.*)\[/URL\]!i'); 
$replacement = array('<img src="\\1">', '<a class="whitearialsm"  href="http://\\1">\\2</a>'); 
}
foreach($data as $element) {
    $element = trim($element);
    $pieces = explode("|", $element);
{
    echo "<form class="form"><b><b><b>". $pieces[1] . "</b></b></b><br><br>" ; 
echo $pieces[2] .  "<br><br>" .  "<small>posted by </small><i><b><b>".$pieces[3].  "</i></b></b><br>on " . $pieces[0] ."</form>"  ; 
} 
}
?>
?>

Posted: Fri Nov 21, 2003 3:51 pm
by Weirdan
hmm... script seems completely mangled to me, where did you get it?
It is easier to rewrite it completely.

Posted: Sat Nov 22, 2003 9:57 am
by mesz
I had a working flatfile forum I had built myself from scratch...then when moving office I managed to delete my local files at the same time as the ones on my remote server and my disk corrupted!!!Very very bad. This was all I was able to cobble together fromn what I had left. It is so frustrating that it worked once and now there is something missing....
please help!!!

Posted: Sat Nov 22, 2003 10:29 am
by ghost007
hi,

It's probably a prog in your reg expr. when you look at the source of your html output what do you get?

BTW: you noticed that you start (<?php) and end php (?>) 2 times?

siech

Posted: Sat Nov 22, 2003 11:56 am
by d3ad1ysp0rk
ghost007 wrote:hi,

It's probably a prog in your reg expr. when you look at the source of your html output what do you get?

BTW: you noticed that you start (<?php) and end php (?>) 2 times?

siech
the double opening and closing are from clicking the

Code: Select all

button (it adds

Code: Select all

<?PHP ?>
)

Posted: Mon Nov 24, 2003 5:54 am
by mesz
I have this

Code: Select all

<?php
$news2 = addLinks($news2); 
$data = file('./news2/news.txt'); 
$data = array_reverse($data);
foreach($data as $element) {
    $ele = trim($ele);
function addLinks($string) { 
$string = preg_replace( 
      "/(?<!quot;|[="]|:\/\/)\b((\w+:\/\/|www\.).+?)". 
     "(?=\W*([<>\s]|$))/i", "<a href="$1" target="_blank">$1</a>", $string); 
return preg_replace("/href="www/i", "href="http://www", $string);} 
}
foreach($data as $element) {
    $element = trim($element);
    $pieces = explode("|", $element);
{
    echo "<form class="form"><b><b><b>". $pieces[1] . "</b></b></b><br><br>" ; 
echo $pieces[2] .  "<br><br>" .  "<small>posted by </small><i><b><b>".$pieces[3].  "</i></b></b><br>on " . $pieces[0] ."</form>"  ; 
} 
}
?>
But I get this error:

Code: Select all

Parse error: parse error in /home/virtual/site140/fst/var/www/html/news2/view.php on line 8

Posted: Mon Nov 24, 2003 8:29 am
by vigge89
You had a dot (.) here:

Code: Select all

<?php
$string = preg_replace(
      "/(?<!quot;|[="]|:\/\/)\b((\w+:\/\/|www\.).+?)". <<<<<<<<
     "(?=\W*([<>\s]|$))/i", "<a href="$1" target="_blank">$1</a>", $string); 
?>
I haven't looked though the whole thing, but i think it needs to be changed to a comma (,)

Posted: Mon Nov 24, 2003 8:53 am
by mesz
That script looked so riddled with errors I tried another approach.
I used the cod ebelow/
However it doesn't REPLACE teh text with the URLs and imgaes, but rather shows BOTH.
How do I stop the text from being displayed?

Code: Select all

<?php
$data = file('./news2/news.dat'); 
$data = array_reverse($data); 
foreach($data as $element) { 
$result = preg_replace('/\\[img\\](.+?)\\[\\/img\\]/', '<img src="\\1">',$pieces[2]); 
$result1 = preg_replace("/\[url=(.+)\](.+)\[\/url\]/Uim","<a href="\\1">\\2</a>",$pieces[2]); 
    $element = trim($element); 
    $pieces = explode("|", $element); 
echo $pieces[2] . 
"<BR>" . 
"<b>Posted by " . 
$pieces[1] . 
" on " . 
$pieces[0] . 
"</b> <BR><BR>". 
$result .
$result1;
} 
?>

Posted: Mon Nov 24, 2003 9:50 am
by mesz
Please can someone explain...I have checked the php mannual and that left me more confused. As far as I can tell the original text should NOT be showing.

Posted: Mon Nov 24, 2003 1:51 pm
by patrikG
mesz wrote:Please can someone explain...I have checked the php mannual and that left me more confused. As far as I can tell the original text should NOT be showing.
What do you mean by "original text" and where is it showing/not supposed to show?

Posted: Tue Nov 25, 2003 2:34 am
by mesz
Cheers for your interest but I have ended up cross posting. The problem has moved to
viewtopic.php?p=71558#71558