0

I have following string

<strong>Test: </strong> BD-F5300

I am interested in getting number BD-F5300. Number could be of any thing text,number.

Any help, how can I get it? Thanks.

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
Ali Nouman
  • 3,304
  • 9
  • 32
  • 53

4 Answers4

2

You could make use of preg_replace

<?php
$str='<strong>Test: </strong> BD-F5300';
echo $str = preg_replace("~<(/)?strong>(.*?)<(/)?strong>~","", $str);

OUTPUT :

BD-F5300

enter image description here

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
2

do like this in JavaScript:

var src = "<strong>Test: </strong> BD-F5300";
var reg = /.*<\/.*>\s*([a-zA-Z0-9-]+)/g;
var group = reg.exec(src);
console.log(group[1]+'\r\n'); //group[1] is what you want !
easynoder
  • 104
  • 4
1

If all you need is to get some content after </strong> then you can just use:

preg_match('@</strong> (.+)@', $string, $matches);

The desired match will be in $matches[1]. However, this requires that the <strong> tag and the text content you want to find are both on the same line. If there are multiples of these you want to match, you may want to use preg_match_all

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
1

If there is always a space before the beginning of the final text you want and if there are never any spaces in the actual number text you want, you can avoid regex by doing this:

$str = '<strong>Test: </strong> BD-F5300';
$solution = substr($str, strrpos($str, ' ') + 1);
var_dump($solution);
Luke Cordingley
  • 665
  • 4
  • 11