• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Make certain characters of a word from string bold

phpregex


PHP Snippet 1:

$text = preg_replace('/\S*('. $searhPhrase .')\S*/i', '<b>$1</b>', $text);

PHP Snippet 2:

$text = preg_replace('/(\S*'. $searhPhrase .'\S*)/i', '<b>$1</b>', $text);

PHP Snippet 3:

function strReplace($searchText,$mainText){
    return str_replace($searchText, '<b>'.$searchText.'</b>', $mainText);
  }

Related Snippets

How to change the app environment at run time?

"properties should not be accessed directly" issue during WooCommerce 3.0 checkout

How can I solve "laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system"?

Limit login attempts in Laravel 5.7

Insert a DIV after the 6th product only once in WooCommerce category archives

Explain how this array transposing and flattening function works

Laravel - How to properly generate unique slugs from article titles?

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

Custom API and cunsuming in php?

php retrieve specific data onclick from database in a list format

php file upload scanning using clamav, permissions on /tmp/

PHP SoapClient: set a namespace without prefix

PHP array_filter with arguments

How update php.ini on a Mac OS X Mojave?

Edit XML in HTML form and submit to self

About Contact Privacy policy Terms and conditions