PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jackjack
Forum Newbie
Posts: 14 Joined: Sat Jul 16, 2005 11:43 pm
Post
by jackjack » Sun Jul 24, 2005 1:09 am
The final putupt of a script is
this piece of code shows any file like so video_file_name.wmv
How do would I get it to just show Video file name, and replace the _ with a space and totally omit the .wmv?
JCART | Please use Code: Select all
tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
nielsene
DevNet Resident
Posts: 1834 Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA
Post
by nielsene » Sun Jul 24, 2005 1:29 am
There's lots of ways. I'm going to show a longer, but easier to understand way. I suspect someone else will chime in with a one-liner preg_replace version, too..
Code: Select all
$docLocation = strrpos($image,'.'); // find the last '.' in the string
if ($docLocation!==FALSE) {
$imageName=substr($image,0,$docLocation); // might need a -1 after $docLocation, never can remember
} else {
$imageName=$image;
$imageName=str_replace("_"," ",$imageName);
jackjack
Forum Newbie
Posts: 14 Joined: Sat Jul 16, 2005 11:43 pm
Post
by jackjack » Sun Jul 24, 2005 2:11 am
Here's my attempt, but it doens't work
Code: Select all
<?php
$nicename = "$image";
$nicename=str_replace("_"," ",$nicename);
$nicename=str_replace(".wmv","",$nicename);
echo "$nicename";
?>
JCART | Please use Code: Select all
tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sun Jul 24, 2005 5:01 am
I'm sorry but it does work
Code: Select all
<?php
$nicename = 'video_file_name.wmv';
$nicename = str_replace("_"," ",$nicename);
$nicename = str_replace(".wmv","",$nicename);
$nicename = ucfirst($nicename);
echo "$nicename";
?>
jackjack
Forum Newbie
Posts: 14 Joined: Sat Jul 16, 2005 11:43 pm
Post
by jackjack » Sun Jul 24, 2005 11:40 am
I don't understand why it's not working.
blah blah blah final output is shown by $image. Then we filter it.
Code: Select all
<?php
$nicename = '$image';
$nicename = str_replace("_"," ",$nicename);
$nicename = str_replace(".wmv","",$nicename);
$nicename = ucfirst($nicename);
echo "$nicename";
?>
what I see is $image on my page.
JCART | Please use Code: Select all
tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Sun Jul 24, 2005 12:20 pm
gotta put double quotes when you want the string to work in quotes
Code: Select all
$nicename = "$image";
//or
$nicename = $image;
both of those will work
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Jul 24, 2005 12:23 pm
jackjack: Please start using the [syntax=php][/syntax] tags around your code.
jackjack
Forum Newbie
Posts: 14 Joined: Sat Jul 16, 2005 11:43 pm
Post
by jackjack » Sun Jul 24, 2005 1:10 pm
Didn't notice the php option.
With worked without the quotes.
Thank you!