news script - link include

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

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

news script - link include

Post 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>"  ; 
} 
}
?>
?>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

hmm... script seems completely mangled to me, where did you get it?
It is easier to rewrite it completely.
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post 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!!!
ghost007
Forum Commoner
Posts: 49
Joined: Sat Nov 22, 2003 10:10 am

Post 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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

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

Post 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
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

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

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

Post 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.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

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

Post by mesz »

Cheers for your interest but I have ended up cross posting. The problem has moved to
viewtopic.php?p=71558#71558
Locked