Oct 28
This simple script makes good things!
1) leave first img tag
2) remove all another img tags
3) cut text by length
So you get simple text short text with one image on it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| function cut_text($x) {
$alli = catch_that_image($x);
if ($alli) {
$x= substr($x, 0, $alli[2]+$alli[3]).
substr(strip_only($x, '<img>'), $alli[2]);
}
if(strlen($x) > 700) {
$x = substr($x, 0, 700);
$y = strrpos($x, '>');
$x = substr($x, 0, $y). '>...';
}
return $x;
}
function catch_that_image($x) {
$first_img = '';
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $x, $matches);
@$first_img = $matches [1][0];
$imglen = strlen($matches [0][0]);
if (strlen($matches [1][0]) AND $imglen){
$imgpos = stripos($x, $matches [0][0]);
$tx = substr($x, 0, $imgpos).substr($x, $imgpos+$imglen); //Vsio krome<img>
}else{
$tx = false;
}
return array($tx,$matches [0][0], $imgpos, $imglen );
}
function strip_only($str, $tags) {
if(!is_array($tags)) {
$tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
if(end($tags) == '') array_pop($tags);
}
foreach($tags as $tag) $str = preg_replace('#</?'.$tag.'[^>]*>#is', '', $str);
return $str;
}
echo cut_text('<div class="content" style="min-height: 202px;">
<img width="200" height="200" alt="Post Pic" src="http://www.wprecipes.com/wp-content/uploads/2009/02/php2.jpg"/>
<div class="pic fl">
<img width="200" height="200" alt="Post Pic" src="http://www.wprecipes.com/wp-content/uploads/2009/02/php2.jpg"/>
</div>
<div class="post-title">
</div>
<img width="200" height="200" alt="Post Pic" src="http://www.wprecipes.com/wp-content/uploads/2009/02/php2.jpg"/>
<div class="post-excerpt">'); |
May 22
How to code url text (links) in PHP and run on JavaScript? read all »
Jan 27
Add to root folder of websitefile bot.php
<?
if (strstr($_SERVER['HTTP_USER_AGENT'], 'Yandex')){ $bot='Yandex';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Googlebot')){$bot='Google';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Mediapartners-Google')){$bot='Mediapartners-Google (Adsense)';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Slurp')){$bot='Hot Bot search';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'WebCrawler')){$bot='WebCrawler search';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'ZyBorg')){$bot='Wisenut search';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'scooter')){$bot='AltaVista';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'StackRambler')){$bot='Rambler';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Aport')){$bot='Aport';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'lycos')){$bot='Lycos';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'WebAlta')){$bot='WebAlta';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'yahoo')){$bot='Yahoo';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'msnbot')){$bot='msnbot/1.0';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'ia_archiver')){$bot='Alexa search engine';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'FAST')){$bot='AllTheWeb';}
if($bot !=""){
$b_data = "bots.txt";
$inf = date("YmdHis",time());
$day = date("d.m.Y",time());
$time = date("H:i",time());
$ip = $REMOTE_ADDR;
$home = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$data = fopen($b_data, "a");
fwrite($data, "$inf|$day|$time|$bot|$ip|$home|rn");
fclose($data);
}
?>
This code tracks visits to your site 15 different bots. Naturally, the list can be extended – is represented by no means all of the existing ones.
Use it, you can read: let’s say your site has a template, and its “assembly” used files header.php ( “cap” of the site) and footer.php ( “basement”). Typically, these files are inserted at the beginning and end of each page on your site.
To carried out statistics on the Hits In of SE bots in this case, you must add the file header.php following code:
Now all the bots will be tracked and kept locked in a file bots.txt on your server.
PS. Do not forget to change CHMOD of bots.txt to 777
Dec 09
chmod for all sub folders 4770, also for siles 660 …
1
2
| find /path -type f -exec chmod 660 {} \;
find /path -type d -exec chmod 4770 {} \; |
Dec 04
easy
so this code …
wget:
download to ./tmp2 dir
from ftp /foldername dir
20 – dir length from main url
1
| wget -r -l20 -P./tmp2 ftp://login:pas@servername/foldername |
Jul 25
phpdug coul not works normal with russian and other languages well in front and backed
to fix this you need just add
1
2
3
4
5
| mysql_query( "set session character_set_server=utf8;", $db_connection );
mysql_query( "set session character_set_database=utf8;", $db_connection );
mysql_query( "set session character_set_connection=utf8;", $db_connection );
mysql_query( "set session character_set_results=utf8;", $db_connection );
mysql_query( "set session character_set_client=utf8;", $db_connection ); |
to
line 81
1
2
3
4
5
6
7
8
9
10
11
| function db_connect($config)
{
$db_connection = @mysql_connect ($config['db']['host'], $config['db']['user'], $config['db']['pass']) OR error (mysql_error(),$config, __LINE__, __FILE__, 0, '');
$db_select = @mysql_select_db ($config['db']['name']) or error (mysql_error(),$config, __LINE__, __FILE__, 0, '');
mysql_query( "set session character_set_server=utf8;", $db_connection );
mysql_query( "set session character_set_database=utf8;", $db_connection );
mysql_query( "set session character_set_connection=utf8;", $db_connection );
mysql_query( "set session character_set_results=utf8;", $db_connection );
mysql_query( "set session character_set_client=utf8;", $db_connection );
return $db_connection;
} |
public_html\includes\functions\func.global.php
Jul 25
Just run in phpmyadmin this rows… read all »
Jun 07
At development of multilingual sites for html-pages most more comfortable and predpochtitel’ney to use the code of Utf-8, providing support all or almost all existent languages and encoding ascii-characters (Roman alphabet, numbers and special characters) by one byte, and national alphabets — a few. Thus, the code of Utf-8 has variable physical length of every character. In this connection sometimes there are problems at programming of multilanguage sites.
For example, in a programming of PHP of function of strlen and substr language give out improper results, if there are characters of national alphabet in a line (as intended for work with an onebyte code). Certainly, in PHP there are such functions as mb_strlen and mb_susbtr, specially intended for work with multibyte lines. But, by default support of Multibyte String Functions in PHP is turned off,that automatically limits the choice of khostinga for the designed site. In addition, during connecting of the module of mb_string the set of the supported languages is specified. And that is why there is probability, that the language required you can not appear in the list of supported.
However, there is other, more comfortable and flexible decision of problem. Taking advantage of functions of PCRE, correctly perceiving the code of Utf-8, it is possible to write the functions of utf8_strlen and utf8_substr:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| function utf8_strlen($s)
{
return preg_match_all('/./u', $s, $tmp);
}
</code>
<code>
function utf8_substr($s, $offset, $len = 'all')
{
if ($offset<0) $offset = utf8_strlen($s) + $offset;
if ($len!='all')
{
if ($len<0) $len = utf8_strlen($s) - $offset + $len;
$xlen = utf8_strlen($s) - $offset;
$len = ($len>$xlen) ? $xlen : $len;
preg_match('/^.{' . $offset . '}(.{0,'.$len.'})/us', $s, $tmp);
}
else
{
preg_match('/^.{' . $offset . '}(.*)/us', $s, $tmp);
}
return (isset($tmp[1])) ? $tmp[1] : false;
} |
Continuing the theme of work with lines in the code of Utf-8, will consider a few functions, workings without set in PHP of expansion of Multibyte String Functions, namely utf8_strpos and utf8_substr_count:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
| function utf8_strpos($haystack, $needle, $offset = 0)
{
# get substring (if isset offset param)
$offset = ($offset<0) ? 0 : $offset;
if ($offset>0)
{
preg_match('/^.{' . $offset . '}(.*)/us', $haystack, $dummy);
$haystack = (isset($dummy[1])) ? $dummy[1] : '';
}
# get relative pos
$p = strpos($haystack, $needle);
if ($haystack=='' or $p===false) return false;
$r = $offset;
$i = 0;
# calc real pos
while($i<$p)
{
if (ord($haystack[$i])<128)
{
# ascii symbol
$i = $i + 1;
}
else
{
# non-ascii symbol with variable length
# (handling first byte)
$bvalue = decbin(ord($haystack[$i]));
$i = $i + strlen(preg_replace('/^(1+)(.+)$/', '\1', $bvalue));
}
$r++;
}
return $r;
}
function utf8_substr_count($h, $n)
{
# preparing $n for using in reg. ex.
$n = preg_quote($n, '/');
# select all matches
preg_match_all('/' . $n . '/u', $h, $dummy);
return count($dummy[0]);
} |