kingless Posted December 1, 2006 at 11:51 PM Report #68231 Posted December 1, 2006 at 11:51 PM Este tópico vai servir para eu postar pequenos scripts PHP que eu vou criando quem quiser também postar alguns mini scripts pode postar a vontade. Aqui fica o primeiro: FUNÇÃO: Esta função faz o oposto da função ucfirst <?php function lcfirst( $frase ) { if(isset( $frase ) AND !is_array( $frase )) { $frase = str_replace( substr( $frase, 0, strlen( $frase )-1 ), strtolower( substr( $frase, 0, strlen( $frase )-1 ) ), $frase ); return $frase; } else { return false; } } $frase = "Esta função faz o oposto de ucfirst!!!"; echo lcfirst( $frase ); ?> FUNÇÃO: Esta função verifica se um email é válido <?php function ValidarEmail ( $email ) { if(preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $email)) { return "O email é válido!!"; } else { return "O email não é válido!!"; } } $email = 'blastelf@hotmail.com'; echo ValidarEmail( $email ); ?>
djthyrax Posted December 2, 2006 at 12:08 AM Report #68238 Posted December 2, 2006 at 12:08 AM function ValidarEmail ( $email ) { if(preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $email)) { return "O email é válido!!"; } else { return "O email não é válido!!"; } } $email = 'blastelf@hotmail.com'; echo ValidarEmail( $email ); Isto não vai funcionar com emails do género lolage@pwnage.da.tia.jaquina.mais.velha.q.o.calhau.do.djthyrax.com 😛 Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum!
kingless Posted December 2, 2006 at 12:28 AM Author Report #68241 Posted December 2, 2006 at 12:28 AM function ValidarEmail ( $email ) { if(preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $email)) { return "O email é válido!!"; } else { return "O email não é válido!!"; } } $email = 'blastelf@hotmail.com'; echo ValidarEmail( $email ); Isto não vai funcionar com emails do género lolage@pwnage.da.tia.jaquina.mais.velha.q.o.calhau.do.djthyrax.com 😛 Não deixa de ser um formato de email valido 😛 Por isso o código diz que é válido... mas para resolver esse problema é só utilizar um código que verifica se o endereço endreço de email existe... http://www.zend.com/zend/spotlight/ev12apr.php http://www.zend.com/codex.php?id=449&single=1
djthyrax Posted December 2, 2006 at 01:07 AM Report #68244 Posted December 2, 2006 at 01:07 AM Não deixa de ser um formato de email valido 😛 Por isso o código diz que é válido... mas para resolver esse problema é só utilizar um código que verifica se o endereço endreço de email existe... http://www.zend.com/zend/spotlight/ev12apr.php http://www.zend.com/codex.php?id=449&single=1 Esquece, n tinha visto um . no preg_match 😛 Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum!
Triton Posted December 3, 2006 at 09:45 PM Report #68553 Posted December 3, 2006 at 09:45 PM FUNÇÃO: Verifica se um email é válido. function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } Uma função que deve funcionar com todos os tipos de email. 😉 <3 life
djthyrax Posted December 3, 2006 at 09:49 PM Report #68556 Posted December 3, 2006 at 09:49 PM @Triton: A do kingless funciona, eu é que não tinha visto um . no preg_match 🙂 EDIT: Não me lembrei dos emails do género djthyrax@123.45.67.89 😉 Neste caso, a do kingless n funca 🙂 Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum!
karva Posted December 3, 2006 at 09:57 PM Report #68557 Posted December 3, 2006 at 09:57 PM Aqui fica um que retorna a tag id3 de um ficheiro .mp3 Função: Retornar as tags id3 dum ficheiro .mp3 <? # getid3 - get id3 v1.1 tag information of an .mp3 file # in: filename # out: array(songname, artis, album, year, comment, genre) else false function getid3 ($file) { if (file_exists($file)) { /* this is done because filesize($fp) gave me false - lost my patiance - ;-( */ $fp=fopen($file,"a+"); $id_start=ftell($fp)-128; fclose($fp); /* "real" code starts here */ $fp=fopen($file,"r"); fseek($fp,$id_start); $tag=fread($fp,3); if ($tag=="TAG") { $id3songname=fread($fp,30); $id3artist=fread($fp,30); $id3album=fread($fp,30); $id3year=fread($fp,4); $id3comment=fread($fp,30); $id3genre=fread($fp,1); $idtag=array(0=>$id3songname,1=>$id3artist,2=>$id3album,3=>$id3year,4=>$id3comment,5=>$id3genre); return $idtag; } else return false; fclose($fp); } else return false; } ?> Proud LEIC-A@IST student!
Triton Posted December 3, 2006 at 10:00 PM Report #68558 Posted December 3, 2006 at 10:00 PM @Triton: A do kingless funciona, eu é que não tinha visto um . no preg_match 😉 Não funciona com todos os tipos de endereços de email. Para mais informações: Email Address Validation. <3 life
karva Posted December 3, 2006 at 10:00 PM Report #68559 Posted December 3, 2006 at 10:00 PM Este cria as tags id3 num ficheiro .mp3 para download, sem afectar o ficheiro original FUNÇÃO: Colocar uma tag id3 num ficheiro .mp3 <? // Script Name: AcidicChip's MP3 ID3v2 Tag Writer 1.0 // // Script Author: Chance O. One (acidicchip@acidicchip.com) // // Script Description: This script will take an MP3 file, with the ID3v2 Tags you want and output them into // a single MP3 file to download. This script will *NOT* edit the MP3 file itself. If // you wish to make this script write the tags to the physical file, instead of the file // that it outputs to download, you will have to make the changes yourself. Please do // not e-mail me, asking me how to do it. Feel free to e-mail me, and let me know of // any bugs it may have. // Change the line below to the path of your MP3 file. eg: $MP3 = "music/mp3/file.mp3"; $MP3 = "TetrisXP.mp3"; // The function below is a reverse function of bin2hex. It will convert hex to binary. function hex2bin($data) { $len = strlen($data); for($i=0;$i<$len;$i+=2) { $newdata .= pack("C",hexdec(substr($data,$i,2))); } return $newdata; } // Change the variable values below to what you want for the ID3v2 Tags. $TrackNum = "01"; $Title = "This is the title"; $Artist = "This is the artist"; $Album = "This is the album"; $Year = "2002"; $Genre = "This is the genre"; $Comment = "This is the comment"; $Composer = "This is the composer"; $OrigArtist = "This is the original artist"; $Copyright = "This is the copyright"; $URL = "This is the url"; $EncodedBy = "This is the encoded by"; // The variables below are converting the values you entered for the tags (above) into hex, in order to // have a better reassurance that your MP3 won't sound funny. $TrackNumHEX = bin2hex($TrackNum); $TitleHEX = bin2hex($Title); $ArtistHEX = bin2hex($Artist); $AlbumHEX = bin2hex($Album); $YearHEX = bin2hex($Year); $GenreHEX = bin2hex($Genre); $CommentHEX = bin2hex($Comment); $ComposerHEX = bin2hex($Composer); $OrigArtistHEX = bin2hex($OrigArtist); $CopyrightHEX = bin2hex($Copyright); $URLHEX = bin2hex($URL); $EncodedByHEX = bin2hex($EncodedBy); // The variables below are creating a hex value for the length of each of the values you entered for the // tags (above). $TrackNumLenHEX = bin2hex(chr((strlen($TrackNum) + 1))); $TitleLenHEX = bin2hex(chr((strlen($Title) + 1))); $ArtistLenHEX = bin2hex(chr((strlen($Artist) + 1))); $AlbumLenHEX = bin2hex(chr((strlen($Album) + 1)));; $YearLenHEX = bin2hex(chr((strlen($Year) + 1)));; $GenreLenHEX = bin2hex(chr((strlen($Genre) + 1))); $CommentLenHEX = bin2hex(chr((strlen($Comment) + 5))); $ComposerLenHEX = bin2hex(chr((strlen($Composer) + 1))); $OrigArtistLenHEX = bin2hex(chr((strlen($OrigArtist) + 1))); $CopyrightLenHEX = bin2hex(chr((strlen($Copyright) + 1))); $URLLenHEX = bin2hex(chr((strlen($URL) + 2))); $EncodedByLenHEX = bin2hex(chr((strlen($EncodedBy) + 1))); // The lines below is the creation of the ID3v2 tags. The tags are usually in this hex format: // XXXXXXXX000000YY0000ZZZZZZZZZZZZZZZZZZZZ // X = The marking for the tag, telling the MP3 player that this tag is right here // Y = The length of the text inputted for the tag (Usually +1) // Z = The content of the tag $Data = "49443303000000000E7A"; $Data .= "5452434B000000" . $TrackNumLenHEX . "000000" . $TrackNumHEX; $Data .= "54454E43000000" . $EncodedByLenHEX . "400000" . $EncodedByHEX; $Data .= "57585858000000" . $URLLenHEX . "00000000" . $URLHEX; $Data .= "54434F50000000" . $CopyrightLenHEX . "000000" . $CopyrightHEX; $Data .= "544F5045000000" . $OrigArtistLenHEX . "000000" . $OrigArtistHEX; $Data .= "54434F4D000000" . $ComposerLenHEX . "000000" . $ComposerHEX; $Data .= "434F4D4D000000" . $CommentLenHEX . "00000000000000" . $CommentHEX; $Data .= "54434F4E000000" . $GenreLenHEX . "000000" . $GenreHEX; $Data .= "54594552000000" . $YearLenHEX . "000000" . $YearHEX; $Data .= "54414C42000000" . $AlbumLenHEX . "000000" . $AlbumHEX; $Data .= "54504531000000" . $ArtistLenHEX . "000000" . $ArtistHEX; $Data .= "54495432000000" . $TitleLenHEX . "000000" . $TitleHEX; // The ID3v2 Tags are EXACTLY 2048 bytes, no matter what. The lines below are filling in the remaining 2048 // bytes (4096 HEX character). $FillIn = (4096 - strlen($Data)); $Data .= str_repeat("0", $FillIn); // The lines below are checking to see if an ID3v2 tag already exists in the MP3. $MusicFile = fopen($MP3, "r"); If (fread($MusicFile, 3) == "ID3") { // If the ID3v2 tag does exist, this line tells it to start the file read after 2048 bytes (The length // of the ID3v2 tags.) fseek($MusicFile, 2048); } // The line below is converting the tags from HEX to binary. $FinalOutput = hex2bin($Data); // The line below is telling your browser that the data that is going to be sent is an MP3 file to download // (or play) header("Content-Type: audio/mp3"); // The line below is uploading your ID3v2 tags. echo($FinalOutput); // The line below is uploading your MP3 file right after the tags (both are being sent as one file) echo(fread($MusicFile,FileSize($MP3))); fclose($MusicFile); ?> Proud LEIC-A@IST student!
Spread Posted December 3, 2006 at 10:02 PM Report #68561 Posted December 3, 2006 at 10:02 PM Ninguém tem praí um scriptzeco que devolva a primeira pasta seguir ao dominio tipo input http://spread-pt.com/pasta/ output pasta Cumps 8) http://spread-pt.comDownload de Hiphop Português gratuito
djthyrax Posted December 3, 2006 at 10:43 PM Report #68574 Posted December 3, 2006 at 10:43 PM Ninguém tem praí um scriptzeco que devolva a primeira pasta seguir ao dominio tipo input http://spread-pt.com/pasta/ output pasta Cumps 8) echo $_SERVER['REQUEST_URI']; se não me engano 😉 Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum!
kingless Posted December 3, 2006 at 11:08 PM Author Report #68588 Posted December 3, 2006 at 11:08 PM karva e Triton obrigado por postarem aqui os códigos 😉 por favor editem o vosso post e coloquem antes do código FUNÇÃO: E_o_que_a_função_faz_aqui É que eu estou a pensar em criar uma pequena "search engine" que vai servir para procurar por códigos neste post e FUNÇÃO:... vai facilitar a pesquisa 🙂
Ped@ntilva Posted December 5, 2006 at 04:26 PM Report #68925 Posted December 5, 2006 at 04:26 PM Muito bom tópico. Estas funções dão imenso jeito.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now