难题:文章内容在MYSQL某字段中,用PHP读取内容,如何将里面的数字,以图片内容输出!
PHP+MYSQL问题:
文章内容放在了MYSQL某字段中,为了防止复制采集,打算把内容里的“阿拉伯”数字,输出为图片格式,我的思路是:用PHP先读取文章内容,然后判断里面的数字,凡是数字的,就显示为图片!效果如图:
问题难点:一篇文章中的数字不止一处,有的达到上百处,而且有的数字是带小数点的,如12.3,这么多的数字,如何输出?
提示:文章是介绍市场行情的,所有数字后面都有一个汉字“元”,如15.6元,14-17元,48元等。
能否通过判断,将“元”前面的若干字符转化为图片输出??
我的分不多了,一共才25分,全给了!
回复讨论(解决方案)
正则替换一下就是了
能处理一个就能处理十个、百个、千个
正则替换一下就是了
能处理一个就能处理十个、百个、千个
本人只懂基础的编程,正则属于高级应用了,弄不了呀!
正则替换一下就是了
能处理一个就能处理十个、百个、千个
本人只懂基础的编程,正则属于高级应用了,弄不了呀!
请求高手指点迷津!!
$con = <<<context广西售价14-17.5元广东零售价23.5元四川零售价13元内蒙零售价0.14元context;$rep = preg_replace('/([\d\.-]+)元/i', '$', $con);var_dump($rep);
$con = <<<context广西售价14-17.5元广东零售价23.5元四川零售价13元内蒙零售价0.14元context;$rep = preg_replace('/([\d\.-]+)元/i', '$', $con);var_dump($rep);
先调试一下再说!
$con = <<<context广西售价14-17.5元广东零售价23.5元四川零售价13元内蒙零售价0.14元context;$rep = preg_replace('/([\d\.-]+)元/i', '$', $con);var_dump($rep);
先调试一下再说!
还是弄不来,我水平太差,初学者。
能看懂上面大致意思,preg_replace 执行查找,但后面如何将数字输出图片呀?如何用图片替换掉文章中的数字呀?
求高手解答!
你在 image 目录中保存一系列数字图片 0.gif、1.gif....
然后
$text = preg_replace('/\d/', '', $text);
你在 image 目录中保存一系列数字图片 0.gif、1.gif....
然后
$text = preg_replace('/\d/', '', $text);
马上调试!!
综合两位大侠的语句,调试结果500错误
<?php$con = <<<context 吴茱萸:货源减少,价格依然较高,目前市场上有批量商品成交,中花品种售价为43-52元,小花、大花品种为37-42元。 栀子:走动较快,现红统价为28-32元。 荆芥:野生品减少,家种品不足,近日走动偏畅,统货价格现为6-7.5元。 香薷草:近年种少,市上商品不多见,本期有零星走动,统货售价为7-11元。 穿心莲:用多,走动较快,批量成交价为7-8元。鱼腥草库存较足,零星走快,价格平稳,统货现为6-8元。 金银花:市货充足,商品有零星走动,价格平稳,目前地产统货售价为45-60元。 红花:有少量成交,价格现为95-97元。杭白菊走少,饼统价为90-110元。百合花走动不多,价格稳定在42-45元。 辛夷花:走动一般,价格趋稳,大花为30-32元,小花为35-37元。 地龙:有小批量货源入市,商品成交以零星为主,广地龙大开为160-175元,中开为95-115元。 蜂房:走动较少,软货市价稳定为250-300元。 水蛭:货源不多,走动也不快,价格趋稳,现清水品为800-900元。 蜈蚣:新品即将上市,走动减慢,现大条2.5-2.7元,中条2.2-2.4元,小条0.9-1.1元。 蛇蜕:市货偏少,价格平稳在100-115元。 党参:交易量减少,价格稳定,目前纹党价为70-85元,白条为45-60元。 玄参:种植面积减少,近来市货不足,走势转畅,现统货价为12-14元。 太子参:货源较足,小批量走动,价格平稳在45-60元。context; $con = preg_replace('/([\d\.-]+)元/i', '<img src="/static/imghw/default1.png" data-src="image/$0.gif" class="lazy" alt="难题:文章内容在MYSQL某字段中,用PHP读取内容,如何将里面的数字,以图片内容输出!" >', $con);var_dump($con);?>
不知上面那里错了,请指教!!!
这样改,也错误
<?php$con = <<<context 吴茱萸:货源减少,价格依然较高,目前市场上有批量商品成交,中花品种售价为43-52元,小花、大花品种为37-42元。 栀子:走动较快,现红统价为28-32元。 荆芥:野生品减少,家种品不足,近日走动偏畅,统货价格现为6-7.5元。 香薷草:近年种少,市上商品不多见,本期有零星走动,统货售价为7-11元。 穿心莲:用多,走动较快,批量成交价为7-8元。鱼腥草库存较足,零星走快,价格平稳,统货现为6-8元。 金银花:市货充足,商品有零星走动,价格平稳,目前地产统货售价为45-60元。 红花:有少量成交,价格现为95-97元。杭白菊走少,饼统价为90-110元。百合花走动不多,价格稳定在42-45元。 辛夷花:走动一般,价格趋稳,大花为30-32元,小花为35-37元。 地龙:有小批量货源入市,商品成交以零星为主,广地龙大开为160-175元,中开为95-115元。 蜂房:走动较少,软货市价稳定为250-300元。 水蛭:货源不多,走动也不快,价格趋稳,现清水品为800-900元。 蜈蚣:新品即将上市,走动减慢,现大条2.5-2.7元,中条2.2-2.4元,小条0.9-1.1元。 蛇蜕:市货偏少,价格平稳在100-115元。 党参:交易量减少,价格稳定,目前纹党价为70-85元,白条为45-60元。 玄参:种植面积减少,近来市货不足,走势转畅,现统货价为12-14元。 太子参:货源较足,小批量走动,价格平稳在45-60元。context; $con = preg_replace('/\d/', '<img src="/static/imghw/default1.png" data-src="image/$0.gif" class="lazy" alt="难题:文章内容在MYSQL某字段中,用PHP读取内容,如何将里面的数字,以图片内容输出!" >', $con);var_dump($con);?>
多了非法字符
报500错,是因为你没打开错误显示功能
$con = <<<context 吴茱萸:货源减少,价格依然较高,目前市场上有批量商品成交,中花品种售价为43-52元,小花、大花品种为37-42元。 栀子:走动较快,现红统价为28-32元。 荆芥:野生品减少,家种品不足,近日走动偏畅,统货价格现为6-7.5元。 香薷草:近年种少,市上商品不多见,本期有零星走动,统货售价为7-11元。 穿心莲:用多,走动较快,批量成交价为7-8元。鱼腥草库存较足,零星走快,价格平稳,统货现为6-8元。 金银花:市货充足,商品有零星走动,价格平稳,目前地产统货售价为45-60元。 红花:有少量成交,价格现为95-97元。杭白菊走少,饼统价为90-110元。百合花走动不多,价格稳定在42-45元。 辛夷花:走动一般,价格趋稳,大花为30-32元,小花为35-37元。 地龙:有小批量货源入市,商品成交以零星为主,广地龙大开为160-175元,中开为95-115元。 蜂房:走动较少,软货市价稳定为250-300元。 水蛭:货源不多,走动也不快,价格趋稳,现清水品为800-900元。 蜈蚣:新品即将上市,走动减慢,现大条2.5-2.7元,中条2.2-2.4元,小条0.9-1.1元。 蛇蜕:市货偏少,价格平稳在100-115元。 党参:交易量减少,价格稳定,目前纹党价为70-85元,白条为45-60元。 玄参:种植面积减少,近来市货不足,走势转畅,现统货价为12-14元。 太子参:货源较足,小批量走动,价格平稳在45-60元。context;$con = preg_replace('/\d/', '<img src="/static/imghw/default1.png" data-src="image/$0.gif" class="lazy" alt="难题:文章内容在MYSQL某字段中,用PHP读取内容,如何将里面的数字,以图片内容输出!" >', $con);var_dump($con);
多了非法字符
报500错,是因为你没打开错误显示功能
$con = <<<context 吴茱萸:货源减少,价格依然较高,目前市场上有批量商品成交,中花品种售价为43-52元,小花、大花品种为37-42元。 栀子:走动较快,现红统价为28-32元。 荆芥:野生品减少,家种品不足,近日走动偏畅,统货价格现为6-7.5元。 香薷草:近年种少,市上商品不多见,本期有零星走动,统货售价为7-11元。 穿心莲:用多,走动较快,批量成交价为7-8元。鱼腥草库存较足,零星走快,价格平稳,统货现为6-8元。 金银花:市货充足,商品有零星走动,价格平稳,目前地产统货售价为45-60元。 红花:有少量成交,价格现为95-97元。杭白菊走少,饼统价为90-110元。百合花走动不多,价格稳定在42-45元。 辛夷花:走动一般,价格趋稳,大花为30-32元,小花为35-37元。 地龙:有小批量货源入市,商品成交以零星为主,广地龙大开为160-175元,中开为95-115元。 蜂房:走动较少,软货市价稳定为250-300元。 水蛭:货源不多,走动也不快,价格趋稳,现清水品为800-900元。 蜈蚣:新品即将上市,走动减慢,现大条2.5-2.7元,中条2.2-2.4元,小条0.9-1.1元。 蛇蜕:市货偏少,价格平稳在100-115元。 党参:交易量减少,价格稳定,目前纹党价为70-85元,白条为45-60元。 玄参:种植面积减少,近来市货不足,走势转畅,现统货价为12-14元。 太子参:货源较足,小批量走动,价格平稳在45-60元。context;$con = preg_replace('/\d/', '<img src="/static/imghw/default1.png" data-src="image/$0.gif" class="lazy" alt="难题:文章内容在MYSQL某字段中,用PHP读取内容,如何将里面的数字,以图片内容输出!" >', $con);var_dump($con);
成功了 http://www.zzyycc.com/ad/ceshi.php

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.
