Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
How to play MP3 from PPHP If Else
<button onclick="playSound()">Play</button>
<script>
function playSound() {
    let src = '../../sounds/paSound.mp3';
    let audio = new Audio(src);
    audio.play();
}
</script>

I have the code above that plays the mp3 sound when clicking the Play button.

What I want to do is to call and play the sound from an if else statement in PHP. Is there a way to do that?

if(statement==true){
 //call playSound js function
}

I have tried the below code: enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It would be better to pass data to JS and then do if/else.

<script>
var jsvar = <?php print $phpvar ;?>
if (jsvar == x) 
play music
</script>

or

<?php if (): ?>

<script>

    let src = '../../sounds/paSound.mp3';
    let audio = new Audio(src);
    audio.play();

</script>
<?php endif; ?>  
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!