int similar_text ( string $first , string $second [, float &$percent ] )
function test(){
static $lock = false;
if(!$lock){
$lock = true; // ф-ция выполняется, больше не выполнять
//выполняем ф-цию
}
}
function test(){
$time = $_SESSION['time'] ?? 0;
if($time < time()){
//выполняем ф-цию
$_SESSION['time'] = time() + 30; // ф-цию можно выполнять раз в 30 сек.
}
}
function test(){
$time = $_COOKIE['time'] ?? 0;
if($time < time()){
//выполняем ф-цию
setcookie('time', time() + 30); // ф-цию можно выполнять раз в 30 сек.
}
}
<td><a href="?delete=<?= $row['id_video'] ?>">[удалить]</a></td>
if (isset($_GET['delete'])){
$query = "DELETE FROM Video WHERE id_video='$_GET[id_video]'";
mysql_query($query);
}
if (isset($_GET['delete'])){
$id = (int) $_GET['delete'];
$query = "DELETE FROM `Video` WHERE `id_video` = '$id' LIMIT 1";
mysql_query($query);
}
function get_idparentcat($cat_parent){
if( $cat_parent == 0 )
{
echo $cat->term_id;
}
else
{
echo $cat_parent;
}
}
get_idparentcat($cat_parent);
function get_idparentcat($cat_parent){
echo !$cat_parent ? $cat->term_id : $cat_parent;
}
$html = new simple_html_dom();
$html->load_file($_GET['go']);
$name = $html->find('h2');
$description = $html->find('div');
$video = $html->find('iframe[width=770]');
$video = $text = preg_replace('/.*\/embed\/(.+)/i', 'https://www.youtube.com/watch?v=$1', $video[0]->src) ;
$description = replace($description[$_GET['id']]->xmltext) ;
$description = preg_replace('/<!.*>.*/is', '', $description) ;
$spoilers = $html->find('div.uSpoilerText') ;
$spoiler = '' ;
foreach($spoilers AS $k => $post){
$text = replace($post->xmltext) ;
preg_match_all("/<!--usn\(\=(.*)\)-->/i", $text, $title);
$text = preg_replace('/<!--ust-->/i', '', $text) ;
$text = preg_replace('/<!--usn\(\=(.*)\)-->/i', '', $text) ;
$text = preg_replace('/<!--\/ust-->/i', '[/spoiler]', $text) ;
//echo $k . ' -> ' . $post->xmltext . '<hr /><br />' ;
$spoiler .= '[spoiler title="' . $title[1][0] . '"]' . $text . "\n\n" ;
}
$description = '[b]Название:[/b] [u]' . $name[0]->plaintext . '[/u] скачать торрент' . $description . $spoiler . $video ;
//$file->meta_description = $title . ' скачать с торрента бесплатно в хорошем качестве' ;
//$file->runame = $name[0]->plaintext ;
$file->description = $description ;
}
$groups = groups::load_ini(); // загружаем массив групп
$form = new form(new url);
$form->text('name', __('Название файла') . ' *', isset($name[0]->plaintext) ? $name[0]->plaintext : $file->runame);
$form->text('link_name', __('Доступен по адресу'), $file->name);
$form->textarea('description', __('Описание'), $file->description);
$form->textarea('description_small', __('Краткое описание'), $file->description_small);
<input type="submit" name="submit" value="no">
<input type="submit" name="submit" value="yes">
$submit = $_POST['submit'] ?? false;
if($submit){
switch ($submit )
{
case 'no' :
echo "нет";
break;
case 'yes' :
echo "да";
break;
}
header('Refresh: 1; ?');
}
$array = [];
$result=mysql_query("SELECT name, vk_access_token, id FROM foxy_groups WHERE user_id = '$uid'");
while($user = mysql_fetch_assoc($result)){
$array[] = $user;
}
echo '<pre>';
print_r($array);
$q = $db->query("SELECT name, vk_access_token, id FROM foxy_groups WHERE user_id = '$uid'");
$result = $q->fetchAll();
echo '<pre>';
print_r($result );
<script type="text/javascript">
$( ".button-reg" ).click(function() {
var mail = $('.form-mail').val();
$.post('add.user.php', {mail: mail}, function(data){
$('.cont').html(data);
});
});
</script>
А это создать add.user.php$mail = $_POST['mail'] ?? false;
if($mail){
//тут запрос в БД
echo 'Вы успешно зарегестрированы'; //если регистрация дейсвительно успешна
}
$url = 'site.ru';
copy('http://mini.s-shot.ru/1024x768/PNG/320/Z100/?' . $url, 'image.jpg');
class Tree {
public $categories = [];
public $categoriesTree = [];
private $db = null;
public function __construct() {
$this->db = new PDO("mysql:dbname=zadanie;host=localhost;charset=UTF8", "root", "");
$this->categories = $this->getCategories();
$this->categoriesTree = $this->getFullTree();
}
/*
* Список всех категорий
*/
private function getCategories(){
$arr_cat = [];
$result = $this->db->query("SELECT * FROM `categories`")->fetchAll();
foreach($result AS $category){
$arr_cat[$category['id']] = $category;
}
return $arr_cat ;
}
/*
* Список категорий в форме дерева
*/
private function getFullTree() {
$tree = [] ;
$categories = $this->categories;
foreach($categories as $id => &$node) {
if(!$node['id_parent']){
$tree[$id] = &$node ;
}else{
$categories[$node['id_parent']]['children'][$id] = &$node ;
}
}
return $tree ;
}
/*
* хлебные крошки
* $id - ID категории в которой мы находимся
*/
public function breadcrumbs($id){
$breadcrumbs_array = [];
$array = $this->categories;
for($i = 0; $i < count($array); $i++){
if($id){
$breadcrumbs_array[$array[$id]['id']] = $array[$id]['title'] ;
$id = $array[$id]['id_parent'] ;
}
}
return array_reverse($breadcrumbs_array, true) ;
}
/*
* @bonus
* Получаем ID всех дочерных категорий родителя
*/
public function getChildren($id_parent){
static $children = [];
$result = $this->db->query("SELECT `id` FROM `categories` WHERE `id_parent` = '$id_parent'")->fetchAll();
foreach($result AS $post){
$children[] = $post['id'];
$this->getChildren($post['id']);
}
return $children;
}
}
$category = new Tree();
$categories = $category->categoriesTree; // список всех категорий
$tree = $category->categoriesTree; // список категорий в форме дерева
$id_categoty = 7; // ID категории в которой мы сейчас находимся
$breadcrumbs = $category->breadcrumbs($id_categoty);
foreach($breadcrumbs AS $id => $title){
if($id == $id_categoty)
continue; // текущую категорию пропускаем
echo ' - <a href="?id=' . $id . '">' . $title . '</a>';
}
$id_parent = 2; // ID категории родителя
$children = $category->getChildren($id_parent);
//print_r($children);