[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Trying to explode a 4 digit number and place <Play> statements in

Posted on 2012-03-27
3
Medium Priority
?
394 Views
Last Modified: 2012-03-27
HI,
I'm generating a random 4 digit code and trying to get some 'Play' statements in between the letters. I'm thinking the code below explains my attempt better. Its wrong, just not sure why its failing.


//get random 4 digit approval id
$approval_id = rand(1001,9998);

//lets assume the random number was 2345
//here I'm not sure if you can explode a string without some kind of separator?

$breakit = explode("", $newapproval_id);

//trying to get new variable to be: <Play>audio/2.wav</Play><Play>audio/3.wav</Play>... and so on

$approval = "<Play>audio/<?php echo $breakit[0]?>.wav</Play><Play>audio/<?php echo $breakit[1]?>.wav</Play><Play>audio/<?php echo $breakit[2]?>.wav</Play><Play>audio/<?php echo $breakit[3]?>.wav</Play>";
?>

Open in new window

0
Comment
Question by:tjyoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Assisted Solution

by:EMB01
EMB01 earned 1000 total points
ID: 37772835
You could use str_split http://php.net/manual/en/function.str-split.php

Here's an example:

$breakit = str_split($newapproval_id);

//trying to get new variable to be: <Play>audio/2.wav</Play><Play>audio/3.wav</Play>... and so on

foreach ($breakit as $a)
{

    $approval .= '<Play>audio/'.$a.'.wav</Play>';

}

echo $approval;
0
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 1000 total points
ID: 37772851
<?php

//get random 4 digit approval id
$approval_id = rand(1001,9998);

// Generate string
$approval = "";
for($i = 0; $i < strlen($approval_id); $i++)
{
  $approval .= "<Play>audio/".substr($approval_id,$i,1) . ".wav</Play>";
}

?>
0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 37772927
Thank you. I used the second one but the first one looked equally promising.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question