Page 1 of 1
Display without the _ and .wmv
Posted: Sun Jul 24, 2005 1:09 am
by jackjack
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]
Posted: Sun Jul 24, 2005 1:29 am
by nielsene
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);
Posted: Sun Jul 24, 2005 2:11 am
by jackjack
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]
Posted: Sun Jul 24, 2005 5:01 am
by timvw
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";
?>
Posted: Sun Jul 24, 2005 11:40 am
by jackjack
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]
Posted: Sun Jul 24, 2005 12:20 pm
by shiznatix
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
Posted: Sun Jul 24, 2005 12:23 pm
by John Cartwright
jackjack: Please start using the [syntax=php][/syntax] tags around your code.
Posted: Sun Jul 24, 2005 1:10 pm
by jackjack
Didn't notice the php option.
With worked without the quotes.
Thank you!
