Forum Moderators: coopster

Message Too Old, No Replies

Replacing each line of a multiline string with a link of itself

Help much appriciated, thanks

         

Vipor

8:16 pm on Dec 12, 2007 (gmt 0)

10+ Year Member



Hi all, my first time posting here and looks like there's a lot of knowledgable people on these boards so hopefully I will be able to get an answer.

I am getting information from an html form to my php page and then sending it as an E-Mail as well. I have a textbox in my form where users enter E-Mails to their website. When my E-Mail gets sent to myself, I would like it so each line has a link of itself, so it would be:
[google.com...]
[facebook.com...]

this would have to be replaced with
<a href="http://www.google.com">http://www.google.com</a>
<a href="http://www.facebook.com">http://www.facebook.com</a>

This is what I have so far:

$links = nl2br($links);
$strHeaders = "MIME-Version: 1.0\r\n";
$strHeaders .= "Content-type: text/html; charset=iso-8859-1\r\n";

$all = "<font face='Arial' color='blue' size='3'><b>2007 Contest</b></font></p>
<html><body><font face='Arial' size='3'>Category: <b>$category </b><br>
<b>$division</b><br><br>
Name of location: <b>$location</b> <br>
Name of submitter: <b>$submitter</b> <br>
Title of submitter: <b>$titlesubmitter</b> <br><br>
Nominee(s): <b>$nominee</b> <br><br>
Publication date(s): <b>$pubdate</b> <br><br>
Links of content: <b>$links</b> <br><br>
Comments: <b>$comments</b></font></body></html>";

mail('dummyemail@gmail.com,$location . " Entry",$all,$strHeaders, "email@gmail.com");

Help is much appriciated, thank you!

[edited by: Vipor at 8:17 pm (utc) on Dec. 12, 2007]

piznac

8:18 pm on Dec 12, 2007 (gmt 0)

10+ Year Member



I really don't understand what you are asking,.. what do you want to be linked?

piznac

8:21 pm on Dec 12, 2007 (gmt 0)

10+ Year Member



Ok wait I see now,. how is this gathered? Can I see the form code?

Vipor

8:25 pm on Dec 12, 2007 (gmt 0)

10+ Year Member



Sure, it's nothing fancy
<form action="m.php" method="POST">
provide the URL<br>
<textarea rows="5" cols="50" name="links"></textarea>
<br>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>

piznac

8:30 pm on Dec 12, 2007 (gmt 0)

10+ Year Member



hmmm you could "explode" them into and array then use a foreach statement to echo them out with the a href. Sorry I don't have the time at the moment to write the code.

Vipor

8:57 pm on Dec 12, 2007 (gmt 0)

10+ Year Member



Thank you piz, but I'm not sure how to do that? I'll give it a try though. In the meanwhile, any other ways?

PHP_Chimp

10:08 pm on Dec 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So I assume that people are entering there links followed by a new line then another link, or are they separating there links with a space or other character?
As if you dont know what character they are going to be using then you may well have to use preg_split [uk2.php.net] to chunk up your links.

Something like -


//$input = $_POST['links'];
$input = "http://www.google.com\nyahoo.co.uk,www.msn.com\n";
$pattern = '%[^\w\.:/]%is';
$split = preg_split($pattern, $input, -1, PREG_SPLIT_NO_EMPTY);
echo '<pre>';
print_r($split);
echo '</pre>';

The second $input is there for me to test it with both new lines http:// addresses no http:// addresses and using ,'s to separate addresses.
So this will split by anything that isnt a word (a-zA-Z0-9_), ., : or /. As these may all be in the url's.

Vipor

10:30 pm on Dec 12, 2007 (gmt 0)

10+ Year Member



Chimp, that looks about right, I just put my coat on and am about to head home but that looks like what i was searching for. Thanks a lot for your help and I will place it in first thing tomorro!

PHP_Chimp

10:48 pm on Dec 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad it helps :)

Iv just noticed that I have is after the expression they can come out, as I they are left there from when I was trying a different expression and are not needed for the present expression to work.