Issues with a php string

They have: 8 posts

Joined: Jan 2009

Hi, I am trying to adapt a php news system I have found online to use on my website. The system is writing the information to a text file, however I am having issues in adding link in the text. However I add them I get the links incorrectly displaying. For example if I want to link to google i get the link pointing to www.mysite.com/www.google.com. Any ideas how I can resolve this? I am literally typing in a normal <a href> tag and everything.

Thanks,

kht

greg's picture

He has: 1,581 posts

Joined: Nov 2005

It's difficult to say without seeing any code at all.

Are you adding your link text to the file like this:
http://www.external-site.com

Because if you are adding it like this (which I'm guessing you are):
external-site.com

Then it will try to send the browser to:
www.your-site.com/external-site.com

If that's not the case, then perhaps the links are specifically defined within the code of the news system you are editing, but I'm guessing (hoping) the above will be the issue.

Also, I edited your post to add the code tags to your link. When using links or code references in your posts on the forum, use the code tags (they are the third icon from the right on the post edit tools).
The forum allows <a href=, and without the code tags it tries to make a link with the text that follows the anchor.

They have: 8 posts

Joined: Jan 2009

Hey greg,

I have tried both methods but get the same error. The code writing the text file is

<?php
//this should all go into one file. I would name it addnews.php
if($HTTP_POST_VARS['submit']) {
    if(
$HTTP_POST_VARS['password'] == 'password') {
        if(!
$HTTP_POST_VARS['name']) {
            echo
"You must enter a name";
            exit;
        }
        if(!
$HTTP_POST_VARS['news']) {
            echo
"You must enter some news";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['name'],"|")) {
            echo
"Name cannot contain the pipe symbol - |";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['news'],"|")) {
            echo
"News cannot contain the pipe symbol - |";
            exit;
        }
       
$fp = fopen('news.txt','a');
        if(!
$fp) {
            echo
"Error opening file!";
            exit;
        }
       
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
       
$line .= "|" . $HTTP_POST_VARS['news'];
       
$line = str_replace("\r\n","&lt;BR&gt;",$line);
       
$line .= "\r\n";
       
fwrite($fp, $line);
        if(!
fclose($fp)) {
            echo
"Error closing file!";
            exit;
        }       
    } else {
        echo
"Bad Password";
    }
}

?>

<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
Your name:<BR>
<INPUT TYPE="text" SIZE="30" NAME="name"><BR>
The News:<BR>
<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA><BR><BR>
News Password:<BR>
<INPUT TYPE="password" SIZE="30" NAME="password"><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Post it!"><BR>
</FORM>

and the code displaying it is:

<?php
$data
= file('news.txt');
$data = array_reverse($data);
foreach(
$data as $element) {
   
$element = trim($element);
   
$pieces = explode("|", $element);
    echo
$pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b><BR><BR>";
}
?>

Thanks for your help and I completely forgot about the code thing previously, my apologies. If you want to see the text file I have been looking at it is found here. It contains the examples of every entry method I have tried Smiling

Thanks again!

They have: 2 posts

Joined: Apr 2009

For example if I want to link to google i get the link pointing to www.mysite.com/www.google.com.

I guess you forgot http:// part before www.google.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.