How To Make Php Output A Sound (beep)?
Solution 1:
php is mostly used on webservers, so what the use beeping there, and you can't beep on user computer through php, as php is translated into HTML, which has no such method.
If you want to have Win32 calls have a look at: How do I make Win32 API calls from PHP? also the Win32 Beep Function
But if you want to have beep sound on user browser better embed audio into the HTML itself.
Edit: Another method for just the beep:
<?phpfunctionbeep ($int_beeps = 1) {
for ($i = 0; $i < $int_beeps; $i++): $string_beeps .= "\x07"; endfor;
isset ($_SERVER['SERVER_PROTOCOL']) ? false : print$string_beeps;
}
?>
This will not do anything when running through a browser, if running through a shell it will produce an audible beep $int_beeps times. This should work on Windows, Unix, etc.
Solution 2:
I tried what Tor Valamo suggested, but I still couldn't get the sound to play.
I would simply get a representation of the chr(7) on my screen but no sound when I used:
system('cmd /k go.bat')
And I would get nothing at all if I used:
exec('cmd /k go.bat')
Instead i used either of:
exec('start /MIN go.bat')
exec('cmd.exe /k start /MIN go.bat')
the only side effect is that a cmd.exe does flash, so the /MIN ensures that it only flashes to the taskbar.
Solution 3:
Update: Never mind, I thought you just wanted a 'beep', not a TONE.
Old post, not answering the question:
You'd need to make a .bat file, so: Open cmd
copycongo.bat[Enter]
@echooff[Enter]echo[Ctrl+G][Enter][Ctrl+Z][Enter]
This looks like:
C:\DEV\test>copy con go.bat
@echo off
echo ^G
^Z
1 file(s) copied.
Now you just call go.bat from PHP through exec() or system() or something. You need to make go.bat through cmd though, in order for the Ctrl+G character to be correct.
Solution 4:
This one works with the standard/built-in beep sound. (more of a 'doink' sound)
Also works on any platform.
Super simple, copy-paste code.
function beep(){
fprintf ( STDOUT, "%s", "\x07" );
}
Solution 5:
EZ way😊:
you can get help form html :
echo "<audiosrc='http://freesoundeffect.net/sites/default/files/incorrect-answer--6-sound-effect-99679566.mp3'autoplay ></audio>";
this code play beep sound in background and you can change .mp3 file
Post a Comment for "How To Make Php Output A Sound (beep)?"