Can anyone please let me know how to seperate Model Numbers from a string

ForEx Titles:
1) Sony DCSW380B 14MP Camera
2) Casio 10MP Camera EX-Z3/3
3) Panasonic Lumix Camera DMC-G1 12MP

Output would be:
For 1) "DCSW380B 14MP" OR ""DCSW380B"
For 2) "10MP EX-Z3/3" OR "EX-Z3/3"
For 3) "DMC-G1 12MP" OR "DMC-G1"

Criteria:
1) All letters of model number are CAPITAL
2) It may include alphabets, numbers or special symbol like "/", "-"
3) Model numbers can be anywhere in the title (not a specific position like 2nd in array on explode)

Not sure if i need to use preg_match fuction.

Please assist. Thanks in advance

Recommended Answers

All 3 Replies

You would need to concat the matches of:

(\b[A-Z0-9/-]*\b)

Are you sure that model numbers are ALWAYS contain at least a number? Or the brand NEVER contain a number? I think you can't just assume that all product will meet this criteria. For instance, "O2 X2i".
It will be even harder since the position of product number is arbitrary.

I think this is human's job

I got the solution.
Here it is:

<?php
$titles = Array('Sony DCSW380B 14MP Camera', 'Casio 10MP Camera EX-Z3/3', 'Panasonic Lumix Camera DMC-G1 12MP');

foreach($titles as $item)
{
    if(preg_match_all('/\b([A-Z0-9\/\-\+]+)\b/', $item, $tmp))
        print implode('||', $tmp[1]).'<br />';
}

?>

Output is separated by "||" in case i need this in future.
Anyway, Thanks in bunch guys for you kind help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.