2016年7月28日 星期四

[swift] imageView Attributes

There are six pictures .


class ViewController: UIViewController {
    @IBOutlet weak var imageShow: UIImageView!

    var arrImg = ["img01","img02","img03","img04","img05","img06"]
    var images:Array<UIImage> = []
    var p:Int = 0
    var count:Int = 0
    override func viewDidLoad() {
        super.viewDidLoad()
        imageShow.image = UIImage(named: arrImg[p])
        count = arrImg.count
        for key in arrImg {
            images.append(UIImage(named: key)!)
        }
        imageShow.animationImages = images
        imageShow.animationDuration = NSTimeInterval(count * 1)
        imageShow.animationRepeatCount = 0
        
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func prevClick(sender: UIButton) {
        p = p - 1
        if p < 0 {
            p = count - 1
        }
        imageShow.image = UIImage(named: arrImg[p])
    }

    @IBAction func nextClick(sender: UIButton) {
        p = p + 1
        if p == count {
            p = 0
        }
        imageShow.image = UIImage(named: arrImg[p])
    }
    @IBAction func playClick(sender: UIButton) {
        imageShow.startAnimating()
    }
    @IBAction func stopClick(sender: UIButton) {
        imageShow.stopAnimating()
    }
    @IBAction func borderClick(sender: UIButton) {
        imageShow.layer.borderColorUIColor.blueColor().CGColor
        imageShow.layer.borderWidth = 3
    }
    @IBAction func roundClick(sender: UIButton) {
        imageShow.layer.cornerRadius = 10.0
        imageShow.layer.masksToBounds = true
    }
    @IBAction func shadowClick(sender: UIButton) {
        imageShow.layer.shadowColor = UIColor.blackColor().CGColor
        imageShow.layer.shadowOffset = CGSizeMake(10.0, 10.0)
        imageShow.layer.shadowOpacity = 0.8
        imageShow.layer.shadowRadius = 5
    }
    @IBAction func normalClick(sender: UIButton) {
        imageShow.layer.borderWidth = 0
        imageShow.layer.cornerRadius = 0
        imageShow.layer.masksToBounds = false
        imageShow.layer.shadowOpacity = 0
    }

}

[PHP] is_array , in_array Function





is_array — Finds whether a variable is an array

<?php
echo is_array(array(1,2,3));  => True
echo is_array('123');     =>False
?>


in_array — Checks if a value exists in an array

<?php
echo in_array('b',array('a','b','c'));   => True
echo in_array('2',array('a','b','c'));   => False
?>

[PHP] is_numeric Function



Finds whether a variable is a number or a numeric string



Example:

<?php

echo is_numeric('33');   => True

echo is_numeric('we');   => False


?>


Returns TRUE if it is a number 

2016年7月26日 星期二

[PHP] print_r pretty print for PHP

Advance print_r in PHP

Example:

<?php

$a = array('1','2','5','8');
print_nice($a);

function print_nice($elem,$max_level=10,$print_nice_stack=array()){
    if(is_array($elem) || is_object($elem)){
        if(in_array($elem,$print_nice_stack,true)){
            echo "<font color=red>RECURSION</font>";
            return;
        }
        $print_nice_stack[]=&$elem;
        if($max_level<1){
            echo "<font color=red>nivel maximo alcanzado</font>";
            return;
        }
        $max_level--;
        echo "<table border=1 cellspacing=0 cellpadding=3 width=100%>";
        if(is_array($elem)){
            echo '<tr><td colspan=2 style="background-color:#333333;"><strong><font color=white>ARRAY</font></strong></td></tr>';
        }else{
            echo '<tr><td colspan=2 style="background-color:#333333;"><strong>';
            echo '<font color=white>OBJECT Type: '.get_class($elem).'</font></strong></td></tr>';
        }
        $color=0;
        foreach($elem as $k => $v){
            if($max_level%2){
                $rgb=($color++%2)?"#888888":"#BBBBBB";
            }else{
                $rgb=($color++%2)?"#8888BB":"#BBBBFF";
            }
            echo '<tr><td valign="top" style="width:40px;background-color:'.$rgb.';">';
            echo '<strong>'.$k."</strong></td><td>";
            print_nice($v,$max_level,$print_nice_stack);
            echo "</td></tr>";
        }
        echo "</table>";
        return;
    }
    if($elem === null){
        echo "<font color=green>NULL</font>";
    }elseif($elem === 0){
        echo "0";
    }elseif($elem === true){
        echo "<font color=green>TRUE</font>";
    }elseif($elem === false){
        echo "<font color=green>FALSE</font>";
    }elseif($elem === ""){
        echo "<font color=green>EMPTY STRING</font>";
    }else{
        echo str_replace("\n","<strong><font color=red>*</font></strong><br>\n",$elem);
    }
}


?>

Result:


[PHP] find the Duplicate values in array using php


Return duplicate values in array using PHP

Example:


<?php

$a = array('1','2','5','8');
$b = array('2','3','4','5');
print_r(array_repeat(array_merge($a,$b)));

function array_repeat($arr){
    if(!is_array($arr))
        return $arr;    
$arr1 = array_unique($arr);    
$arr3 = array_diff_key($arr,$arr1);    
return array_unique($arr3);}



?>

Result:

array $a



array $b



array_merge($a,$b)


array_repeat(array_merge($a,$b))







[PHP] Regular Expression to URL removed in PHP


Regular Expression to URL removed in PHP


Example:

<?php

    preg_match_all('/<a.*?href=".*?">(.*?)<[\/]a>/', $content,$arr);
    
    $new_content = str_replace($arr[0], $arr[1], $content);
    echo $new_content;


?>

Source:
$content='The author is occupied with handling solutions for quite sometimes and he has years of experience in <br />
<a href="http://www.optimumgroup.com.au/product-details/Outdoor-Dangerous-Goods-Storage/51" rel="nofollow">Outdoor Dangerous Goods Storage</a> and Line Shaft Conveyors. OHS is a premium company for handling <a href="http://www.optimumgroup.com.au/product-details/Line-Shaft-Conveyors/26" rel="nofollow">solutions</a> in Sydney. ';


Result:

$arr





$new_content


The author is occupied with handling solutions for quite sometimes and he has years of experience in 
Outdoor Dangerous Goods Storage and Line Shaft Conveyors. OHS is a premium company for handling solutions in Sydney.

 

[PHP] Regular Expression get Image Src

Regular Expression


Example:

<?php

$pattern = '/<img.*?src="(.*?)" .*?\/>/';
preg_match_all($pattern, $content,$img_arr);
print_r($img_arr);

?>

Source:

$content="<p> &nbsp; <img class="alignnone size-full wp-image-40188" src="http://img2.localhost/img/news/78/e2/78e2780f351d33ca38b93c677bc9578a.jpg" alt="18" width="750" height="500" />
If you are reading this article, chances are you are a Project Management Professional (PMP) and then you know what PDU stands for.

&nbsp; <img class="alignnone size-full wp-image-40186" src="http://img2.localhost/img/news/22/a6/22a66b54003dc506eea9b7fc93299723.jpg" alt="7" width="750" height="500" />
If not, Professional Development Units (PDU) are like credits that every PMP needs to earn in order to keep their certification.
 &nbsp; <img class="alignnone size-full wp-image-40187" src="http://img2.localhost/img/news/2d/66/2d66c300244ef31e57790203bea0870d.jpg" alt="18" width="750" height="500" />  &nbsp; &nbsp; &gt;&gt;&nbsp;</strong>&nbsp;<strong>http://housetube.tw</strong> <strong>&nbsp;</strong> &nbsp;</p>";

Reslut:

$img_arr