/    Sign up×
Community /Pin to ProfileBookmark

formatting a string

I have an admin section on my site that allows a user to upload a pdf in the format of Week_mmddyyyy.pdf. What I want to do, is when I display this on the screen, display it like:

Week of July 28, 2008

How would I do this? right now, I am displaying it as “Week of 07282008” using this code:

[code=php]
$displayname = str_replace(“_”,” of “,$file);
$displayname = str_replace(“.pdf”,””,$displayname);
[/code]

Thanks

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ss1289Jul 29.2008 — [code=php]preg_match_all('/(d{2})(d{2})(d{4})/', $file, $result);
$displayname = date("F j, Y", mktime(0,0,0,$result[1],$result[2],$result[3]));[/code]


preg_match_all using a regular expression to separate them accordingly into an array called $result. mktime() takes those values and converts them to a month, day, year. Then date() converts them to the string that you want.

Actually I misread your code. You'll have to seperate the date numbers from the rest. Because my $file variable is equal to '07282008'
Copy linkTweet thisAlerts:
@jrthor2authorJul 29.2008 — I get this error when trying your code:

[B]Warning[/B]: mktime() expects parameter 4 to be long, array given on in ... on line 46

Which is this line:

[COLOR=#000000][COLOR=#0000bb]$displayname [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]date[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]"F j, Y"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]mktime[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]0[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]0[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]0[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$result[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]],[/COLOR][COLOR=#0000bb]$result[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]2[/COLOR][COLOR=#007700]],[/COLOR][COLOR=#0000bb]$result[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000bb]3[/COLOR][COLOR=#007700]])); [/COLOR][/COLOR]

Just an fyi, printing out the $result array, I have this:

Array ( [0] => Array ( [0] => 07272008 ) [1] => Array ( [0] => 07 ) [2] => Array ( [0] => 27 ) [3] => Array ( [0] => 2008 ) )
Copy linkTweet thisAlerts:
@ss1289Jul 29.2008 — hmm, interesting, I have the same output for $result and it works perfect for me. We must have different php versions.

try:

mktime(0,0,0,$result[1][0],$result[2][0],$result[3][0])

and see what happens.
Copy linkTweet thisAlerts:
@jrthor2authorJul 29.2008 — Thanks, that worked
×

Success!

Help @jrthor2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.9,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...