14 апреля 2008 ~ 4764 Комментария

Приятные мелочи на php

php

PHP-logo-140_74px

Пишу эту заметку для себя, вдруг мне пригодиться, в моем компьютере потеряется, а тут на блоге останется навсегда — да и Вам может пригодиться ;-).

Две маленькие функции на php:

  • Определение Тематического Индекса Цитирования
  • Многоязычный переводчик

Определение ТИЦ

Берет значения тИЦ напрямую из Яндекс.Каталога, очень быстрая скорость работы. Писал не Я, писал Владимир.

<?php
function yandex_tic($url){
$file=file_get_contents("http://search.yaca.yandex.ru/yca/cy/ch/$url/");
if(preg_match("!—\s+([0-9]{0,8})<\/b>!is",$file,$ok)){
// сайт не в каталоге.
$str=$ok[1];
        }
        else if(preg_match("!<td class=\"current\" valign=\"middle\">(.*?)</td>\n</tr>!si", $file, $ok)){
                if(preg_match("!<td align=\"right\">(.*?)</td>\n</tr>!si", $ok[0], $str)){
// сайт в каталоге.
$str=$str[1];
                } else {
$str=0;
                }
        }
        else {
$str=0;
        }
return trim($str);
}
// Пример:
// echo yandex_tic("zhilinsky.ru")
?>

Многоязычный переводчик

Работает через Google Переводчик.

Работает быстро. Писал Я, на коленке, поэтому криво, если будут замечания — пишите! Я исправлюсь ;-)

<?php
function translate($text,$lg) {
$lg = urlencode($lg);
$text = urlencode($text);
$link = file_get_contents("http://google.com/translate_t?langpair=$lg&text=$text");
preg_match('/<div id=result_box dir=\"ltr\">(.*?)<\/div>/', $link, $out);
return $out[1];
} 

// Пример:
// echo translate("hello")

// Пример c другим языком(С Английского на Немецкий):
// echo translate("hello", "en|de")
?>

4764 Комментария для “Приятные мелочи на php”

  1. You…are…my…hero!!! I cant believe something like this exists on the internet! Its so true, so honest, and more than that you dont sound like an idiot! Finally, someone who knows how to talk about a subject without sounding like a kid who didnt get that bike he wanted for Christmas.

  2. koaorpa 21 мая 2012 at 23:54 Permalink

    Приятные мелочи на php | Ð§ÐµÑ€Ð½ÐµÐ².ру Very nice post. I just stumbled upon your blog and wished to say that I’ve really enjoyed browsing your blog posts. After all I will be subscribing to your feed and I hope you write again very soon!

  3. lacoste outlet online 22 мая 2012 at 0:33 Permalink

    Of course, what a splendid site and informative posts, I surely will bookmark your site.Best Regards!

  4. ephedra fat burners 22 мая 2012 at 0:33 Permalink

    Simply wanna remark on few general things, The website style and design is perfect, the subject material is real great : D.

  5. kasor 22 мая 2012 at 0:53 Permalink

    Приятные мелочи на php | Ð§ÐµÑ€Ð½ÐµÐ².ру Pretty nice post. I just stumbled upon your blog and wished to say that I have truly enjoyed surfing around your blog posts. After all I will be subscribing to your feed and I hope you write again very soon!

  6. koaorpa 22 мая 2012 at 1:12 Permalink

    Приятные мелочи на php | Ð§ÐµÑ€Ð½ÐµÐ².ру Pretty nice post. I just stumbled upon your blog and wished to say that I’ve truly enjoyed browsing your blog posts. In any case I’ll be subscribing to your rss feed and I hope you write again soon!

  7. phen375 customer reviews 22 мая 2012 at 1:14 Permalink

    I loved as much as you will receive carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get got an edginess over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly very often inside case you shield this increase.

  8. Spanduk 22 мая 2012 at 1:15 Permalink

    I dugg some of you post as I cerebrated they were extremely helpful handy

  9. koaorpa 22 мая 2012 at 1:16 Permalink

    Nice post at Приятные мелочи на php | Ð§ÐµÑ€Ð½ÐµÐ².ру. I was checking continuously this blog and I’m impressed! Very useful info particularly the last part :) I care for such information much. I was seeking this particular info for a very long time. Thank you and good luck.

  10. koaorpa 22 мая 2012 at 1:27 Permalink

    Приятные мелочи на php | Ð§ÐµÑ€Ð½ÐµÐ².ру Pretty nice post. I just stumbled upon your blog and wished to say that I’ve truly enjoyed surfing around your blog posts. After all I will be subscribing to your rss feed and I hope you write again very soon!


Оставить комментарий