• 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

Failing validation doesn't stop code execution in livewire component

merging two arrays with specified index

How to use React Router with Laravel?

woocommerce_wp_select options array from product attribute terms

How to debug in WooCommerce 3+

How to get total pages of PDF with FPDF?

How to connect to MSSQL Server with PHP from Ubuntu 18.04?

Get WooCommerce products from specific category

Symfony Mercure "Failed to send an update"

Add bold text and line break into Laravel Notification Email

Alert message after submitting form in PHP

Laravel 5 controller sending JSON integer as string

Yii2: How do I debug console commands?

How to convert a carbon into string, to take the date only?

Fatal error: Uncaught mysqli_sql_exception: Unknown database 'test' in ... (How do I fix that? Using PHP)

About Contact Privacy policy Terms and conditions