_Chris Posted April 14, 2008 Share Posted April 14, 2008 Hi all, Was recommended here as you're all a very helpful lot Basically, the code below, gets information from another page, but in the string for the day, it's coming in as the full name and for the date string, it's coming in as the full name for the month - with str_replace how do you get all days of the week and all months of the year, to change to the first 3 letters please ? ie, Monday changes to Mon, Tuesday to Tue, April changes to Apr, October changes to Oct? $table8 .= "\n".'<td class="styles1"><div class="day">'.date('l',strtotime($dates[1][$i].' '.date('Y'))).'</div><div class="date">'.$datestr.'</div>'.str_replace('<span>Two</span>','',str_replace('Three.','Four',$Six[0][$i])).'</td>'; Any help much appreciated. Chris. Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/ Share on other sites More sharing options...
chigley Posted April 14, 2008 Share Posted April 14, 2008 substr() should do the job Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-516837 Share on other sites More sharing options...
Zhadus Posted April 14, 2008 Share Posted April 14, 2008 chigley's way will definitely work. Additionally, however, I would recommend reviewing date() as you can format it's output to only display Mon-Sun and Jan-Dec. Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-516842 Share on other sites More sharing options...
_Chris Posted April 14, 2008 Author Share Posted April 14, 2008 Crikey, I was told that you lot were not only helpful but very quick as well - looks as though it was the total truth How would you change the code below to reflect the amendments please : $table8 .= "\n".'<td class="styles1"><div class="day">'.date('l',strtotime($dates[1][$i].' '.date('Y'))).'</div><div class="date">'.$datestr.'</div>'.str_replace('<span>Two</span>','',str_replace('Three.','Four',$Six[0][$i])).'</td>'; Chris. Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-516851 Share on other sites More sharing options...
chigley Posted April 14, 2008 Share Posted April 14, 2008 <?php $table8 .= "\n".'<td class="styles1"><div class="day">'.substr(date('l',strtotime($dates[1][$i].' '.date('Y'))), 0, 3).'</div><div class="date">'.substr($datestr, 0, 3).'</div>'.str_replace('<span>Two</span>','',str_replace('Three.','Four',$Six[0][$i])).'</td>'; ?> ^ Give that a whirl. Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-516856 Share on other sites More sharing options...
_Chris Posted April 14, 2008 Author Share Posted April 14, 2008 Many thanks for the quick help Chigley - that did the trick for shortening the days, but it's now changed the dates from, for example, 18 April to just 18 ? Chris. Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-516874 Share on other sites More sharing options...
Zhadus Posted April 14, 2008 Share Posted April 14, 2008 Change the 3 in the substr() methods to 6. It will cut off everything past the 6th character. Unfortunately I'm not sure if you'd get values like "2 April" or if it would be "02 April" with the original string. Else it would give you "18 Apr" and "2 Apri" from using that method. Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-516898 Share on other sites More sharing options...
chigley Posted April 14, 2008 Share Posted April 14, 2008 Where you define $datestr, in your date() function, use M instead of m and remove the substr() bit. Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-516916 Share on other sites More sharing options...
soycharliente Posted April 14, 2008 Share Posted April 14, 2008 He needs to use M and D. Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-516928 Share on other sites More sharing options...
chigley Posted April 14, 2008 Share Posted April 14, 2008 M is the short version of the month. Is that not what I just said? Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-516932 Share on other sites More sharing options...
soycharliente Posted April 14, 2008 Share Posted April 14, 2008 Is that not what I just said? Yeah. I misread and took it out. My post now really is to show that he needs to use D as well. Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-517053 Share on other sites More sharing options...
_Chris Posted April 14, 2008 Author Share Posted April 14, 2008 Many thanks for the quick help on this - it's really appreciated. I'm now using the code below, and is giving the correct format, but are you saying that it would it give me 02 Apr on the 2nd of April, and not 2 Apr ? <?php $table8 .= "\n".'<td class="styles1"><div class="day">'.substr(date('l',strtotime($dates[1][$i].' '.date('Y'))), 0, 3).'</div><div class="date">'.substr($datestr, 0, 6).'</div>'.str_replace('<span>Two</span>','',str_replace('Three.','Four',$Six[0][$i])).'</td>'; ?> Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-517065 Share on other sites More sharing options...
soycharliente Posted April 15, 2008 Share Posted April 15, 2008 One thing someone was saying is that there is no need to use substr with l (lowercase L) because D can do exactly what you want. It's setup for MANY different types of output, all of which you can find online here. So one thing you can do is change this: substr(date('l',strtotime($dates[1][$i].' '.date('Y'))), 0, 3) to: date('D', strtotime($dates[1][$i].' '.date('Y'))) I'm not exactly sure what your variables hold, but I'd be willing to bet you could clean up a lot of your code in general by looking at what you can do with date/strtotime/mktime. Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-517264 Share on other sites More sharing options...
_Chris Posted April 16, 2008 Author Share Posted April 16, 2008 Many thanks for all the help - problem solved, this is obviously a very helpful forum here Link to comment https://forums.phpfreaks.com/topic/101076-solved-can-anyone-lend-a-hand-with-str_replace-please/#findComment-518790 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.