PHP

PHP { 11 }

Tuesday, 03 April 2018 00:43

[solved] How to delete text symbol from php line?

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

How to show all errors in php?

Written by
Rate this item
(2 votes)

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');
Last modified on Thursday, 14 December 2017 16:16
Rate this item
(3 votes)
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;
}

 

Friday, 20 October 2017 19:19

Unset Joomla Scripts from Template (k2 and other)

Written by
Rate this item
(3 votes)
// Unset unwanted Scripts - by name
$unset_scripts = array(
	'k2',
	'...',
);

foreach($this->_scripts as $name=>$script)
{
	if (!preg_match('#(' . implode('|', $unset_scripts) . '#i', $name))
	{
		continue;
	}

	unset($this->_scripts[$name]);
}

or if you use joomla v3.8.1 you can try this php code:

<?php
	$doc = JFactory::getDocument();
	unset($doc->_scripts[JURI::root(true) . '/media/system/js/mootools-more.js']);
	unset($doc->_scripts[JURI::root(true) . '/media/system/js/mootools-core.js']);
	unset($doc->_scripts[JURI::root(true) . '/media/system/js/core.js']);
	unset($doc->_scripts[JURI::root(true) . '/media/system/js/modal.js']);
	unset($doc->_scripts[JURI::root(true) . '/media/system/js/caption.js']);
	unset($doc->_scripts[JURI::root(true) . '/media/jui/js/jquery.min.js']);
	unset($doc->_scripts[JURI::root(true) . '/media/jui/js/jquery-noconflict.js']);
	unset($doc->_scripts[JURI::root(true) . '/media/jui/js/bootstrap.min.js']);
?>

if you wand disable all js & css scripts - use code:

$doc->_scripts     = null;
$doc->_script      = null;
$doc->_styleSheets = null;

 

Last modified on Tuesday, 24 October 2017 23:08
Friday, 30 June 2017 19:44

How to trim String text in php

Written by
Rate this item
(4 votes)

For example we have text

<strong>
                     
                         
                            The Times
                          
                        NY
                     
                </strong>

 But good result need be

<strong>The Times NY</strong>

 I make regexp in php

function trim_text($str)                             
{                                                    
    return trim(preg_replace('/\s{2,}/', ' ', $str));                                                 
}

 

Thursday, 15 December 2016 14:43

Mac how to Upgrade php v5 to php v7

Written by
Rate this item
(3 votes)

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

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

Thursday, 28 April 2016 15:34

[ solved ] Fatal error: Cannot redeclare

Written by
Rate this item
(3 votes)
<?php  

if ( ! function_exists ( 'yours_func' )) {
    function yours_func() {
     ...
    }
 }

?>

 

Rate this item
(3 votes)

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());

?>