KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have an If-else statement which checks a string to see whether there is an ISBN-10 or ISBN-13 (book ID). The problem I am facing is with the ISBN-10 check which occurs before the ISBN-13 check, the ISBN-10 check will match anything with 10 characters or more and so may mistake an ISBN-13 for an ISBN-10. here is the code... $str = "ISBN:9780113411436"; if(preg_match("/\d{9}(?:\d|X)/", $str, $matches)){ echo "ISBN-10 FOUND\n"; //isbn returned will be 9780113411 return 0; } else if(preg_match("/\d{12}(?:\d|X)/", $str, $matches)){ echo "ISBN-13 FOUND\n"; //isbn returned will be 9780113411436 return 1; } How do I make sure I avoid this problem?
Tags (comma-separated)
Save Edits
Cancel