views:

965

answers:

3

What's the PHP verson of this python code?

import winsound
winsound.Beep(537, 2000)
+3  A: 

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:

<?php
  function beep ($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.

Priyank Bolia
Believe it or not, but it's even possible to make desktop apps with PHP and GTK+...
Tor Valamo
yes there winbinder application allowing to create desktop apps with php :)
Sarfraz
I know, but i used the word 'mostly', I never seen anyone writing a desktop apps with PHP
Priyank Bolia
I know a guy who probably would, if I didn't constantly hack away at him for suffering from PHP fanboyness... :P
Tor Valamo
maybe he needs a beep on his server for every web access... like a Geiger counter. Think about it, it's not that bad as idea :)
Stefano Borini
This is not equivalent PHP version.
@unknown That's because there is no easy, equivalent PHP version.
deceze
I showed you the way, what you mean by the equivalent PHP. I don't think there is any other way other then embedding audio (either through flash like justin said) or using Win32 API for server.
Priyank Bolia
@Stefano: That would be incredibly annoying for anyone working near that server :P
Tor Valamo
+1,it's near,but it can't control frequency.
A: 

http://stackoverflow.com/questions/907942/is-it-possible-to-make-beep-sound-in-php-like-in-gmail

echo
The python code I provided doesn't require installing of any flash.
yeah, well, PHP doesn't provide Windows beep libraries. So you get what you pay for.
echo
A: 

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

copy con go.bat [Enter]
@echo off [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.

Tor Valamo
But still you can't see the freq and duration, you need to use Win32 Beep API for that.
Priyank Bolia