• 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

Timber: Single post pagination does not work (wp_link_pages)

Upgrade PHP on AWS Linux

Read users and passwords from a txt file

How to display MySQL table using php and edit it in a web browser

Laravel display validation error

Convert every two values of an associative array into key-value pairs

How to unlink image from folder?

get folder directory from input type file - PHP

php mysql + create a friend request system

Adding one microsecond to Datetime object in PHP

Insert multidimensional array to codeigniter cart

I can't delete my image when it is liked because of the foreign key in mysql

How do I call a php file with axios?

Unsure why I am getting: Number of variables doesn't match number of parameters in prepared statement

With doctrine ODM, can I embed many subdocuments in a main document?

About Contact Privacy policy Terms and conditions