UK Webmaster Talk - Online Marketing - SEO


 

Seperation Of Values

This is a discussion on Seperation Of Values within the Programming Articles forums, part of the Webmaster Articles/Tutorials category; This is a handy little tut, if you want to have the capability, of using just one input, to do ...


Go Back   UK Webmaster Talk - Online Marketing - SEO > Webmaster Articles > Webmaster Articles/Tutorials > Programming Articles

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Notices

Reply

 

LinkBack Thread Tools Display Modes
Old 29-04-2005, 21:31   #1 (permalink)
WMT Addict
 
Join Date: Apr 2005
Posts: 120
iTrader: 0 / 0%
Shwaza will become famous soon enough
Default Seperation Of Values

This is a handy little tut, if you want to have the capability, of using just one input, to do something for each value in it.

First of all, we're going to use the function explode() to seperate our values. To begin, here's simple little script, that you could use to email people depending on emails submitted by someone, seperating them with line breaks.

PHP Code:
<?php
if($_POST['submit']){
$emails=$_POST['emails'];
$email=explode(chr(13), $emails);
foreach(
$email as $email){
mail($email"You've been referred""You have been referred by mr. blah, to do.....""email@email.com");
}
}
else{
echo 
"<form action='"$PHP_SELF"' method='post'>
Enter as many emails as you would like, with a line break between them:<br />
<textarea name='emails'></textarea><br />
<input type='submit' name='submit' value='Send'>
</form>"
;
}
?>
First of all, we see that if 'submit' has been posted, and then simplify the submitted emails into the variable $emails:
PHP Code:
if($_POST['submit']){
$emails=$_POST['emails']; 
Next, we define a new variable $email, to be exploded into an array of all the emails someone has submitted, seperating them with line breaks:
PHP Code:
$email=explode(chr(13), $emails); 
With explode(), you first string the seperating charactor or phrase, then the origional value to seperate ($emails in this case), then if you want, you can string a limit on how many you will allow, however i didn't add that for this tutorial.

Now that we have all the emails submitted into an array, we'll use forreach(){} to send an email to each of those emails individually:
PHP Code:
foreach($email as $email){
mail($email"You've been referred""You have been referred by mr. blah, to do.....""email@email.com");

Of course, you could make it a much or interesting message (lol), but this is just an example. Also, remember to change email@email.com to your email address :P

Then, we just have the else{} part of the script, which just echos out the form for a user to submit their emails.
PHP Code:
else{
echo 
"<form action='"$PHP_SELF"' method='post'>
Enter as many emails as you would like, with a line break between them:<br />
<textarea name='emails'></textarea><br />
<input type='submit' name='submit' value='Send'>
</form>"
;

That's just a simple tut, but i like it, because i find that explode() is quite a usefull little function. It can be used for several things, and you don't always need to use it in an array. Say you had a variable which you only wanted to keep the first sentance of, you could use this:

PHP Code:
$sentance="Blah blah blah blah. More blah more blah more blah.";
$newsentance=explode('.'$sentance);
echo 
$newsentance[0]; 
And that will just echo the first sentance, then if you changed the 0, every time it increases, it would display the next sentace

I hope some of you find this usefull
__________________
Kingdoms Of Battle << Check out my free to play online strategy game!

SomeCoders - Coding blog, coding tips
Shwaza is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
seperation, values

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 19:22.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
UK Webmaster Forum © WebmasterTalk.co.uk | Design by Forbairt

Ad Management by RedTyger

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41