Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String separation using ; and store in an array 2

Status
Not open for further replies.

iranor

Programmer
Joined
Jun 17, 2004
Messages
174
Location
CA
I want to set-up a mail system on my website.

I want user to be able to put multiple users as destination.

The name would be separated with a ; , then a value for each name is stored in the database.

Wich string should I use to do that?

I only needs to add the name in an array , then i'll be able to add them in the database.

Exemple , the "to" field of a form contains : name1;name2;name3

How can I add these in an array to be able to add them in the db?
 
Iguess $name_array=explode(';',$_POST/GET[to]);

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks , this works well!

I wonder how I can scan the same field , named tomsg for the value *.

I need to scan , because if a user type * in the tomsg field , i need to send the message to everybody.

To test , i made this basic form :

<form method='post'>
<input type=text name=tomsg>
<input type=hidden name=page value=compose2>
<input type=submit value=Send>
</form>
<?
if($page=="compose2"){
if(ereg("*",$_POST['tomsg'])) {
send_to_all();
}
else
{
$name_array=explode(';',$_POST['tomsg']);
foreach($name_array as $users){
echo "$users<br>";
}
}
}
}
?>

When i put users in tomsg like user1;user2;user3 , everything is fine.

How can I make a scan in this field for * ? because now i'm getting this error :

Warning: ereg(): REG_BADRPT in /home/neomaster/ on line 9
 
When you use the asterisk * in regular expressions as a literal it has to be escaped. Otherwise it has meta character meaning of zero or no occurrences.
I'd also use preg() instead of ereg().

Sometimes it is argued that strstr() is faster than a regular expression - for a single lookup however it might be negligable.
 
Thanks! I used strstr and the everything works fine.

<form method='post'>
<input type=text name=tomsg>
<input type=hidden name=page value=compose2>
<input type=submit value=Send>
</form>
<?
if($page=="compose2"){
if(strstr($tomsg, '*')){
send_to_all();
}
else
{
$name_array=explode(';',$_POST['tomsg']);
foreach($name_array as $users){
echo "$users<br>";
}
}
}
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top