[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

trimming strings

Posted on 2006-06-22
3
Medium Priority
?
208 Views
Last Modified: 2006-11-18
i have 67 strings that can vary in what values they hold.

an example is:

MS 300 Series - Management System Monitoring and Non Conformance Control/MS-301 Internal Audit Report.doc
MS 300 Series - Management System Monitoring and Non Conformance Control/MS-302 - The Corrective Action Process.vsd
MS 300 Series - Management System Monitoring and Non Conformance Control/MS-302 Corrective Action Request.doc
MS 300 Series - Management System Monitoring and Non Conformance Control/MS-303 - Preventive Action.vsd
MS 300 Series - Management System Monitoring and Non Conformance Control/MS-310 - Assessment of Contractors Sht 1.vsd

but i only what to display:

MS-301 Internal Audit Report
MS-302 - The Corrective Action Process
MS-302 Corrective Action Request
MS-303 - Preventive Action
MS-310 - Assessment of Contractors Sht 1

... im not too sure how to trim both the beginning and the end...
0
Comment
Question by:ellandrd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 2000 total points
ID: 16962230
Hi ellandrd,

Well, you seem to only want the end, and conveniently, there is a / between them and a . between the extension. You can merely do:

$a_strings = array();
$a_strings[] = 'MS 300 Series - Management System Monitoring and Non Conformance Control/MS-301 Internal Audit Report.doc';
$a_strings[] = 'MS 300 Series - Management System Monitoring and Non Conformance Control/MS-302 - The Corrective Action Process.vsd';
//etc.etc.

$a_parsed_strings = array();
foreach ($a_strings as $v)
{
    $slash_pos = strrpos($v, '/');
    $dot_pos = strrpos($v, '.');
    $a_parsed_strings[] = substr($v, $slash_pos + 1, $dot_pos - $slash_pos - 1);
}

print_r($a_parsed_strings);

Regards,
Ted
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16962342
Hi, you may also want to try regular expressions...

<?php
$strarr = array();
$strarr[] = 'MS 300 Series - Management System Monitoring and Non Conformance Control/MS-301 Internal Audit Report.doc';
$strarr[] = 'MS 300 Series - Management System Monitoring and Non Conformance Control/MS-302 - The Corrective Action Process.vsd';
// ... add as many strings as required, or get from database..

$req = array();
foreach ($strarr as $str)
{
    preg_match("#/([-\s\w]+)\.#s",$str,$match);
    $req[] = $match[1];
}

print_r($req);
?>


---
Harish
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 16962375
Yep, regular expressions will also work as well, and is probably a better bet if the format of your strings start to become a bit more irregular.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question