PHP: Select part of string (from to) and apply changes on it -


i want way change part of string according simple marks. example:

$string = "i'm student (at jic college), , i'm genius."; 

i want select at jic college or words between brackets , change color. (i know how change color). how select change put back. , how if had more 1 brackets.

$string = "i'm student (at jic college), , i'm genius (not really)."; 

you use preg_replace achieve this.

$string = "i'm student (at jic college), , i'm genius (not really).";  $string = preg_replace('/\(([^\)]+)\)/', '<span style="color:#f00;">$1</span>', $string); 

unfortunately example little unclear chosen encapsulation gets lost in regex , needs escaping. i'd use other brackets if you're making code clear!


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -