Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

php random string

Trying to generate something like



324523@dhr.com
4534@dhr.com

Where the numbers are generated randomly... can someone help on the syntax?


// random number
	

//var $email= " rand(1,100000). "@" ."dhr.com" " ;
$rand            = rand( 1, 100000 );

$email     .= ". $rand ." = '". @ ."' + 'dhr.com';";

Open in new window

0
TonyReba
Asked:
TonyReba
  • 4
  • 3
  • 2
  • +1
1 Solution
 
Tyler LaczkoCommented:
//var $email= " rand(1,100000). "@" ."dhr.com" " ;
$rand            = rand( 1, 100000 );

$email     = $rand . "@dhr.com";
0
 
TonyRebaAuthor Commented:
this gives me an error
class moscomprofilerUser extends moscomprofiler  {
      /** @var string */
      var $name                              =      null;
      /** @var string */
      var $username                        =      null;
      /** @var string */
      
// random number
      
//var $email= " rand(1,100000). "@" ."dhr.com" " ;
$rand            = rand( 1, 100000 );

$email     = $rand . "@dhr.com";


Is is because is within a class? if so how can I called this variable?
0
 
Tyler LaczkoCommented:
You should be placing a new question for that.

You do not use the keyword var in PHP.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Ray PaseurCommented:
There are a couple of layers to this question that while they may appear subtle, actually make a great deal of difference to the code you would choose.

Do you need these to be numbers only?  Do these strings need to be a certain length?  Do they need to be unique (never duplicated).  Do you need to keep track of them so you can reproduce a test?  How many such random strings do you need?
0
 
Mohamed AbowardaSoftware EngineerCommented:
Simply:
$email = rand(1, 100000) . "@dhr.com";

Open in new window

0
 
Ray PaseurCommented:
Well, TonyReba, if you won't answer our questions and leave the questions open and unattended it's hard to help you.  The accepted solution is one possible answer.  And if it is one you like, maybe you should tell us why you did not give any points at all to the correct and complete answer that you got less than ten minutes after you posted the question.  Your accepted solution is the same answer as the one posted at 35741283.
0
 
Mohamed AbowardaSoftware EngineerCommented:
Actually, it's considered to be more simple and easier to understand than the answer in #35741283.
0
 
Ray PaseurCommented:
Maybe for you it is.  I prefer an atomic approach to programming over the compound statements.  But if you want to split hairs over the solutions, neither is satisfactory because neither can generate this:

324523@dhr.com

If I were professionalcomputersolutions I would ask a moderator to reopen the question so TonyReba can clarify his selection.
0
 
Mohamed AbowardaSoftware EngineerCommented:
@Ray_Paseur: professionalcomputersolutions posted possible solution and I posted possible solution too, however, the author preferred my solution.

It happens alot of times that I post a solution and the author accept another solution and sometimes the opposite, since the author accepted possible solution and the comment is not irrelevant, they don't have to clarify why they chose that comment, at the end the auther choose which solution worked for them and they preferred.
0
 
Ray PaseurCommented:
It's OK, medo3337.  I've been here in the EE forum for a while and every now and then I see an accepted solution that does not make sense in the context of the question.  Life's like that.  America elected Woodrow Wilson, Jimmy Carter and George Bush.  They're poor presidents but good men, all different, and there are many ways to answer technical questions, all different.

Over and out, ~Ray
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now