• 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

Reorder attribute dropdown terms in Woocommerce single variable products

Object of class stdClass could not be converted to string error

RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev)

PHP DOTENV unable to load env vars

disable two buttons after clicking another button

Facebook API, get page post link (PHP)

Elasticsearch - Want to sort by field in all indices where that particular field available or not if not then avoid it

How to get unique slug to same post-title for other time too?

Laravel implode array items to new lines

Laravel after login Two factor not working

laravel sanctum Route [login] not defined

nginx err_connection_refused, can anyone help me?

WHERE IN array binding in DB::raw laravel 5.4

Input and output values for php into the browser?

Creating live search with AJAX and CodeIgniter

About Contact Privacy policy Terms and conditions