In PHP string I want extract ID and replace with name player -
i extract #id1234 , use function replace name in link form.
the id number dynamic.
so from
$string = 'hello #id1234 , rest of text';
to
$string = 'hello , <a href="#">john</a> , rest of text';
i need function name , sort link. okay code not sure how extact #id1234 convert player number 1234.
the player number can put anyway easy , fast extract ideas welcome ie {1234}
assuming function get_name($id)
returns name of user, try:
preg_match_all('/\d+/', $string, $id); $name = get_name($id) preg_replace("/#id[0-9]*/", "<a href='/whatever_url?id=".$id."'>".$name."</a>", $string);
Comments
Post a Comment