search
HomeBackend DevelopmentPHP Tutorial网上的一段代码哪里错了?

<?php/** * 电话号码识别. * @author by zsc for 2010.03.24 */ class gjPhone{  protected $imgPath;//图片路径      protected $imgSize;//图片大小  protected $hecData;//分离后数组  protected $horData;//横向整理的数据  protected $verData;//纵向整理的数据   function __construct($path){      $this->imgPath = $path;  }/** * 颜色分离转换... * * @param unknown_type $path * @return unknown */  public function getHec()    {           $size = getimagesize($this->imgPath);        $res = imagecreatefrompng($this->imgPath);                for($i=0; $i < $size[1]; ++$i)        {               for($j=0; $j < $size[0]; ++$j)            {                $rgb = imagecolorat($res,$j,$i);                $rgbarray = imagecolorsforindex($res, $rgb);                               if($rgbarray['red'] < 125 || $rgbarray['green']<125                || $rgbarray['blue'] < 125)                {                    $data[$i][$j]=1;                }else{                    $data[$i][$j]=0;                }            }        }        $this->imgSize = $size;        $this->hecData = $data;    }/** * 颜色分离后的数据横向整理... * * @return unknown */public function magHorData(){        $data = $this->hecData;    $size = $this->imgSize;        $z = 0;    for($i=0; $i<$size[1]; ++$i)       {         if(in_array('1',$data[$i])){            $z++;            for($j=0; $j<$size[0]; ++$j)            {                   if($data[$i][$j] == '1'){                                       $newdata[$z][$j] = 1;                }else{                   $newdata[$z][$j] = 0;                 }            }                  }         }    return $this->horData = $newdata;} /** * 整理纵向数据... * * @return unknown */public function magVerData($newdata){    for ($i=0;$i<132;++$i){        for($j=1;$j<13;++$j){            $ndata[$i][$j] = $newdata[$j][$i];        }    }      $sum = count($ndata);    $c = 0;    for ($a=0;$a<$sum;$a++){        $value = $ndata[$a];        if(in_array(1,$value)){                          $ndatas[$c] = $value;              $c++;        }elseif(is_array($ndatas)){          $b = $c-1;          if(in_array(1,$ndatas[$b])){              $ndatas[$c] = $value;              $c++;          }        }             }     return $this->verData = $ndatas; }/** * 显示电话号码... * * @return unknown */public function showPhone($ndatas){    $phone = null;    $d = 0;    foreach ($ndatas as $key => $val){        if(in_array(1,$val)){            foreach ($val as $k => $v){               $ndArr[$d].=$v;            }        }                if(!in_array(1,$val)){            $d++;        }    }   foreach ($ndArr as $key01 =>$val01){        $phone .= $this->initData($val01);   }      return $phone;}/** * 分离显示... * * @param unknown_type $dataArr */function drawWH($dataArr){    if(is_array($dataArr)){        foreach ($dataArr as $key => $val){            foreach ($val as $k => $v){                if($v == 0){                    $c .= "<font color='#FFFFFF'>".$v."</font>";                }else{                  $c .= $v;                }            }            $c .= "<br/>";        }        }    echo $c;}    /**     * 初始数据...     *     * @param unknown_type $numStr     * @return unknown     */    public function initData($numStr){        $result = null;        $data = array(            0=>'000011111000001111111110011000000011110000000001110000000001110000000001110000000001011000000011011100000111000111111100000001110000',            1=>'011000000000011000000000111111111111111111111111',            2=>'001000000011011000000111110000001101110000011001110000011001110000110001111001100001011111100001000110000001',            3=>'001000000010011000000011110000000001110000000001110000110001110000110001011001110011011111011111000110001100',            4=>'000000001100000000111100000001111100000011101100000111001100001100001100011000001100111111111111111111111111000000001100000000000100',            5=>'111111000001111111000001110001000001110001000001110001100001110001100001110000110011110000111111000000001100',            6=>'000011111000001111111110011000110011110001100001110001100001110001100001110001100001010001110011010000111111000000001100',            7=>'110000000000110000000111110000111111110001110000110111000000111100000000111000000000111000000000',            8=>'000100011110011111111111110011100001110001100001110001100001110001100001110011100001011111111111000100011110',            9=>'001111000000011111100001110000110001110000110001110000110001110000110001011000100001011111100111000111111110000001110000',        );        foreach ($data as $key => $val){           similar_text($numStr,$val,$pre);           if($pre>95){//相似度95%以上               $result = $key;               break;           }        }        return $result;    }} $imgPath = "http://bj.ganji.com/tel/5463013757650d6c5e31093e563c51315b6c5c6c5237.png";$gjPhone = new gjPhone($imgPath);//进行颜色分离$gjPhone->getHec();//画出横向数据$horData = $gjPhone->magHorData();echo "===============横向数据==============<br/><br/><br/>";$gjPhone->drawWH($horData);//画出纵向数据$verData = $gjPhone->magVerData($horData);echo "<br/><br/><br/>===============纵向数据==============<br/><br/><br/>";$gjPhone->drawWH($verData); //输出电话$phone = $gjPhone->showPhone($verData);echo "<br/><br/><br/>===============电话==============<br/><br/><br/>".$phone;?>



这是一段完整的代码,为什么最后不显示电话号码呢,横向和纵向都显示了
//输出电话
$phone = $gjPhone->showPhone($verData);
echo "


===============电话==============


".$phone;

这段不显示


回复讨论(解决方案)


这是电话号码吗?

http://www.ganji.com/tel_img/?c=kd1LqjAmJoJICgLz3V2gnIbW.eoBw__PtQyX
用这个也不显示
多几个横杠也不行?

要纯数字????

看起来蛮NB的,图片识别,不懂~~

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Atom editor mac version download

Atom editor mac version download

The most popular open source editor