0

I have string contain numbers. I only want to get numbers. please help. Thank guys.

<?php
$a = '<td>15</td>';
?>
bambostar
  • 45
  • 8
  • 1
    Possible duplicate of [Extract numbers from a string](https://stackoverflow.com/questions/6278296/extract-numbers-from-a-string) – Wasim K. Memon Jul 21 '17 at 10:34

4 Answers4

2

You can use strip_tags

<?php
$a = '<td>15</td>';
echo strip_tags($a);
Nishant Nair
  • 1,999
  • 1
  • 13
  • 18
1
$int = filter_var($a, FILTER_SANITIZE_NUMBER_INT);
Shubham Agrawal
  • 559
  • 6
  • 15
0

preg_match_all will help you. See this.

$a = '<td>15</td>';
preg_match_all('!\d+!', $a, $matches);
print_r($matches);
Virb
  • 1,639
  • 1
  • 16
  • 25
0

I think using strip_tags is the good way.

http://php.net/manual/fr/function.strip-tags.php

<?php
$a = '<td>15</td>';
$number = strip_tags($a);
?>
Royce
  • 45
  • 1
  • 1
  • 9