$string = 'Some Text .... 1. 2 .3.  Buy';
$string = preg_replace('~[^0-9]+~','',$string);
echo $string;
// 123 
Thursday, 14 December 2023 15:59

How to show all errors in php?

If you need show some errors in your php code - use this php notation:

// enable showing errors in PHP
ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT);
ini_set('display_errors','On');
function compresscss ( $data, $url ) {
        global $current_css_url;
        $current_css_url = $url;
        /* remove comments */
        $data = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $data);
        /* remove tabs, spaces, new lines, etc. */
        $data = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), ' ', $data);
        /* remove unnecessary spaces */
        $data = preg_replace('/[ ]+([{};,:])/', '\1', $data);
        $data = preg_replace('/([{};,:])[ ]+/', '\1', $data);
        /* remove empty class */
        $data = preg_replace('/(\}([^\}]*\{\})+)/', '}', $data);
        /* remove PHP code */
        $data = preg_replace('/<\?(.*?)\?>/mix', '', $data);
        /* replace url*/
        $data = preg_replace_callback('/url\(([^\)]*)\)/', 'replaceurl', $data);
        return $data;
}

 

During 2017, we have heard a lot of opinions that this year has been too gloomy for Joomla. However, we think that this year is so important because it is the stepping stone for the explosion in 2018 when we prepare to welcome Joomla! 4.0 and Joomla! Framework 2.0. In addition to introducing several new features, including a fully rebuilt Media Manager, an enhanced event dispatching system, and new security features such as support for prepared SQL statements, we have also been doing some routine maintenance and paying off some of our project’s technical debt by retiring deprecated code and raising the minimum supported software stack. And, with this released version, we also require PHP 7.

Thursday, 15 December 2023 14:43

Mac how to Upgrade php v5 to php v7

We will proceed by installing PHP 5.5, PHP 5.6, PHP 7.0, and PHP 7.1 and using a simple script to switch between them as we need.

$ brew install php55 --with-apache
$ brew unlink php55
$ brew install php56 --with-apache
$ brew unlink php56
$ brew install php70 --with-apache
$ brew unlink php70
$ brew install php71 --with-apache

 Let's do it!

brew install php71

Or use this code and install php 7.3 without brew

curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3

and after that run this in terminal

export PATH=/usr/local/php5/bin:$PATH

But, we looking Error:

==> Installing php71 from josegonzalez/php
Error: Cannot install josegonzalez/php/php71 because conflicting formulae are installed.
  php55: because different php versions install the same binaries.
Please `brew unlink php55` before continuing.
Unlinking removes a formula's symlinks from /usr/local. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.

Dont panic! :-) Run unlink command:

brew unlink php55

# Unlinking /usr/local/Cellar/php55/5.5.38_11... 17 symlinks removed

Then try again:

brew install php71
# ==> Summary
# ?  /usr/local/Cellar/php71/7.1.0_11: 342 files, 39.7M

Then try our php version

php -v

PHP 7.1.0 (cli) (built: Dec  2 2016 03:30:24) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies

What you can do if you type php -v and show php v5.5?

open terminal and put this code and press Enter

export PATH=/usr/local/php5/bin:$PATH

 

<?php
// получаем параметры компонента com_users
$params = JComponentHelper::getParams('com_users');
// устанавливаем требуемое значение
$params->set('guest_usergroup', '1');
// записываем измененные параметры в БД
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->update($db->quoteName('#__extensions'));
$query->set($db->quoteName('params') . '= ' . $db->quote((string)$params));
$query->where($db->quoteName('element') . ' = ' . $db->quote('com_users'));
$query->where($db->quoteName('type') . ' = ' . $db->quote('component'));
$db->setQuery($query);
$db->execute();
?>

In this example, it is important to pay attention to the reduction of the variable $params to string. As a result of this reduction JRegistry object it will be converted into JSON format and you want to record in the field params #__extensions table.

$params = JComponentHelper::getParams('com_users');
var_dump($params);

 

$catid = JRequest::getInt( 'catid', 1, 'get' );
$articleid = JRequest::getInt( 'id', 1, 'get' );

Or you can use enother choise

$uri = JURI::getInstance();
$app = & JFactory::getApplication('site');
$router = & $app->getRouter();
$getParams = $router->parse($uri);
echo '<pre>'; print_r ($getParam); echo '</pre>';

 

public static function getUserId($username)
{
    $db = JFactory::getDbo();
    $query = $db->getQuery(true)
        ->select($db->quoteName('id'))
        ->from($db->quoteName('#__users'))
        ->where($db->quoteName('username') . ' = ' . $db->quote($username));
    $db->setQuery($query, 0, 1);
    return $db->loadResult();
}

And you can use JUserHelper:

$username = 'admin';
$userId    = JUserHelper::getUserId($username);
echo $userId;
Thursday, 28 April 2023 15:34

[ solved ] Fatal error: Cannot redeclare

<?php  
if ( ! function_exists ( 'yours_func' )) {
    function yours_func() {
     ...
    }
 }
?>

 

Check on the user group membership in joomla:

	/*
	* Function 
	*/
function getAccess($groups=array(), $user_id=0)
	{
		if ($user_id == 0) $user_id = JFactory::getUser()->id;
		echo $user_id;
		if (count($groups) == 0 || $user_id == 0) return false;
		return (count(array_intersect(JFactory::getUser($user_id)->getAuthorisedGroups(), $groups))>0);
	}
// Print groups user id 
	print_r($user_id = $user->getAuthorisedGroups());
// Output Group Access Permissions
    $groups = array(18, 8);// an array of groups separated by commas
    if(getAccess( $groups)) echo 'Access granted to groups 18 and 8';
	

Use simple script

<?php
/**
 * @param $path
 */
function readDir($path){
	$d=dir($path);  
	while(false!==($entry=$d->read())){
	  if(($entry== '.')||($entry=='..'))continue; 
			if(is_dir($path.'/'.$entry)){
				readDir($path.'/'.$entry);
			}  
	echo $path.'/'.$entry."<br />\n";  
	}  
	$d->close();  
}
readDir(getcwd());
?>

To replace Teg you should run a query UPDATE. First you need to go to K2-> Tags and find out under what id is required tags. Next in phpMyadmin we insert sql query code like this:

-- If we want to replace the tag id 6 wherever there is tag with id 12, the request will be so
UPDATE `you_prefix_k2_tags_xref` SET `tagID` = '6' WHERE `you_prefix_k2_tags_xref`.`tagID` =12;