Zado
asked on
Remove elements of string
Hi,
I have a string like so:
2009-1178(10)-1323(11)-201 0-2186(18) -2596(21)- 2010-3950( 32)-4477(3 7)
And want to remove repeating year numbers from the string, so final output for string above would be:
2009-1178(10)-1323(11)-201 0-2186(18) -2596(21)- 3950(32)-4 477(37)
So I need a script doing the following work:
- check if there's repeated year numbers (format=[four_digits][hyph en]);
- if so - remove second year number and leave the first one (as in example string above);
Thanks for any help.
I have a string like so:
2009-1178(10)-1323(11)-201
And want to remove repeating year numbers from the string, so final output for string above would be:
2009-1178(10)-1323(11)-201
So I need a script doing the following work:
- check if there's repeated year numbers (format=[four_digits][hyph
- if so - remove second year number and leave the first one (as in example string above);
Thanks for any help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help guys, I'm just checking your scripts.
Thanks Ray, I also thought about create separate columns for each year in mysql database, would be much better to maintain the data I think.
Thanks Ray, I also thought about create separate columns for each year in mysql database, would be much better to maintain the data I think.
Yes, I would think that might be one way to do it. Or you could have a table with (at least) two columns and as many rows as needed. One column would be the DATETIME (which could contain the year, as well as more precise timestamp information) and the other column(s) could contain the associated data elements.
ASKER
Thanks for advice. One more thing: can I use your script to affect all rows in database? I mean this:
mysql_connect("localhost","admin","*******");
@mysql_select_db("pcpm") or die( "Unable to connect with database");
$result = mysql_query("SELECT * FROM catalogue_data");
while ($row=mysql_fetch_assoc($result))
{
$str=($row['db_column']);
// your script here
}
I have some problems when I use your script this way, or maybe I do something wrong.
Which script
Show us the CREATE TABLE statement. I am sure we can show you some good ways to get the data out.
ASKER
Ray's one.
galexander07, I found one problem in yours: it removes also repeated regular numbers from string - numbers with brackets, not years. Well, that would make script even better, but yours removes same number in different years, example of 'before' and 'after' below:
2009-1178(10)-1323(11)-201 0-2186(18) -1323(11)- 2596(21)
2009-1178(10)-1323(11)-201 0-2186(18) -2596(21)
galexander07, I found one problem in yours: it removes also repeated regular numbers from string - numbers with brackets, not years. Well, that would make script even better, but yours removes same number in different years, example of 'before' and 'after' below:
2009-1178(10)-1323(11)-201
2009-1178(10)-1323(11)-201
ASKER
I fixes it, just cleaned $year variable at the end or the script:
mysql_connect("localhost","admin","*******");
@mysql_select_db("pcpm") or die( "Unable to connect with database");
$result = mysql_query("SELECT * FROM catalogue_data");
while ($row=mysql_fetch_assoc($result))
{
$str=($row['db_column']);
// your script here
$year='';
}
Thanks a lot for your help.
Open in new window