If you just want to filter everything other than the numbers out, the easiest is to use filter_var:
$str="In My Cart : 11 items";
$int = (int) filter_var($str, FILTER_SANITIZE_NUMBER_INT);
More Related Contents:
- Get last whole number in a string
- Convert a comma-delimited string into array of integers?
- Converting an integer to a string in PHP
- Converting a number (1, 2, 3) to a string (one, two, three) in PHP
- How do I check if a string contains a specific word?
- Split a comma-delimited string into an array?
- Passing base64 encoded strings in URL
- Using str_replace so that it only acts on the first match?
- Converting string to Date and DateTime
- Capturing text between square brackets in PHP
- Remove multiple whitespaces
- How do I remove all specific characters at the end of a string in PHP?
- Dollar ($) sign in password string treated as variable
- Replace last occurrence of a string in a string
- How can I check if a word is contained in another string using PHP?
- Remove a string from the beginning of a string
- What is the most efficient way to count all the occurrences of a specific character in a PHP string?
- How to get first x chars from a string, without cutting off the last word?
- How can I remove part of a string in PHP? [closed]
- Find first character that is different between two strings
- PHP String Manipulation: Extract hrefs
- How to convert PascalCase to snake_case?
- PHP – Add link to a URL in a string
- How to strip trailing zeros in PHP
- Include constant in string without concatenating
- Remove Trailing Slash From String PHP
- Measure string size in Bytes in php
- Explode a paragraph into sentences in PHP
- Format 32-character string with hyphens to become UUID
- finding common prefix of array of strings