• 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

Do I need to install `fxp/composer-asset-plugin` if I'm not doing front-end development

Wordpress how to get the post thumbnail inside a figure tag

How can I pass the list to the component variable in Laravel?

Laravel/docker-compose/redis - Class 'Redis' not found

Laravel Carbon throws error The format separator does not match

How do I do HTTP basic authentication using Guzzle?

Yii Ajax Submit button

How to get rid of ampersand using WP Nonce URL and WP Redirect or PHP header

Spam Filter in Contact Form

Laravel Passport - Not able to get token string in response?

Getting public posts of a random user from Facebook API

Entity provider not working in security.yml php symfony3.4 ({"code":401,"message":"bad credentials"}.)

If action is on a different page do I use fwrite function

HTML + PHP + PHPMAILER

GuzzleHttp Hangs When Using Localhost

About Contact Privacy policy Terms and conditions