search
HomeBackend DevelopmentPHP TutorialPHP smarty's ubb plug-in implements colored words_PHP tutorial

PHP smarty's ubb plug-in implements colored words_PHP tutorial

Jul 13, 2016 pm 05:29 PM
phpsmartyoneunderforaccomplishplug-inmethodyesofSimple

Colored characters are popular recently, here is a simple way to implement them:

1. Simple implementation of colorful characters

以下为引用的内容:
header("content-type: image/png");
$text = $_get[t];
$font = stxingka.ttf; //ttf字体
$fontsize = 30;
$size = imagettfbbox($fontsize, 0, $font, $text); //获得字体长宽范围
$dx = abs($size[2]-$size[0]) +10;
$dy = abs($size[5]-$size[3]);
//构建图像
$im = imagecreate($dx,$dy);
imagecolorallocate($im, 255,255, 255); //背景色
$fontcolor = imagecolorallocate($im, 255, 0, 0); //字体颜色
imagettftext($im, $fontsize, 0, 0, abs($size[5]), $fontcolor, $font, $text);
imagepng($im);
imagedestroy($im);

The above program only expresses some basic principles of color words. To achieve more complex and beautiful color words, all you need to do is to change the font, change the font color, add some background images, and then consider caching, etc. The methods are similar, friends can try it themselves.

2. Color word application

The colored words generated by the above program are transmitted through "?t=text", but it should be noted that these words are best encoded with urlencode. Of course, the length should also be limited. This is not discussed in this article. Range.
In addition, the program that generates colored words and the program that transmits text both use utf-8 encoding. If not, convert it manually...
To use colored words, just use PHP smarty's ubb plug-in implements colored words_PHP tutorial That's it, where color.php is the program that generates colored words (that is, the program above), and xxx is the text encoded by urlencode (used to generate colored words)

Three.smarty plug-in

Create a new file modifier.ubb.php in smarty’s plugins directory with the following content:

The following is the quoted content:
以下为引用的内容:
function smarty_modifier_ubb($string){
    $ubb = array(
        /[b](.+?)[/b]/i, #加粗
        /[url=(.+?)](.+?)[/url]/i, #url
        /[colorfont](.+?)[/colorfont]/ie #彩字,注意,要加e修饰符
    );
    $tohtml = array(
        1,
        2,
        "PHP smarty's ubb plug-in implements colored words_PHP tutorial"
    );
    //以上只是演ubb的实现,更多的ubb标签朋友们可以按方法自己实现,其中的color.php根椐实际去修改
    return preg_replace($ubb,$tohtml,$string);
}
function smarty_modifier_ubb($string){ $ubb = array(

/[b](.+?)[/b]/i, #Bold
/[url=(.+?)](.+?)[/url]/i, #url
                                                                                                                                                                                                                   ;1,

2, “PHP smarty's ubb plug-in implements colored words_PHP tutorial" );

//The above is just the implementation of ubb. Friends can implement more ubb tags according to the method. The color.php root is actually modified

return preg_replace ($ubb,$tohtml,$string);
In this way, to display colored words, just add [colorfont] text[/colorfont] to the content. When displaying , use the ubb modifier in the smarty template, such as {$content|ubb } http://www.bkjia.com/PHPjc/531680.html
www.bkjia.comtrue
http: //www.bkjia.com/PHPjc/531680.htmlTechArticleColored characters are popular recently, and the following is a simple implementation method: 1. Simple implementation of colored characters The following is the quoted content : header("content-type: image/png"); $text = $_get[t]; $font = stxingka.ttf;...
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
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

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 Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.