Category Archives: xml parsing

PHP How to remove numbers from string?

Hey there,

While parsing any document (HTML, XML or aything!), You might have involved in a stage where you would need to remove numeric values (numbers) from the string. PHP has some useful function which will make this easy as butter..:)

The above PHP code makes use of the functions range(), str_replace(), trim().

range() : Create an array containing a range of elements

str_replace() : Replace all occurrences of the search string with the replacement string

trim() : Strip whitespace (or other characters) from the beginning and end of a string

That’s all. Share it..Enjoy Coding..Cheers..:)


XML Parsing with PHP DomDocument : Examples

Sample XML file for testing

Getting all Car names from all persons:

Getting all Car colors from all persons:

Joining Car names & Colors together for all persons: