-1
<?php  
  $name = "product_"
  $lens = strlen($name - 8); 
  $id = substr($name , 8 , $lens);
  $query = query("SELECT * FROM product WHERE product_id= ".escape_string($id)." ");
?>

I want to take the id of product, but when I try it I see:

A non-numeric value encountered in strlen($name - 8);

Is there another way to do it?

Decent Dabbler
  • 22,532
  • 8
  • 74
  • 106

1 Answers1

0

I think you mean

$lens = strlen($name) - 8;

but you don't actually need $lens, because you can just do

$id = substr( $name, 8 );

That will automatically give you the remaining characters.

Now, the reason you are getting the warning, is because of this. In other words, you are trying to subtract a number from a string:

$name - 8
Decent Dabbler
  • 22,532
  • 8
  • 74
  • 106