Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

problem with printing only part of changing string

$
0
0

hey guys, i'm try to print part of the string only and i'm trying with substr and strripos and stripos.

<!DOCTYPE html>
<html>
<body>
<?php
$str= '/lalala/temp/index.html';
echo 'html = ' . strripos($str, "html");
echo '<br />';
echo 'html = ' . substr($str, stripos($str,"temp/") +5);
echo '<br />';
echo 'html = ' . substr($str, stripos($str,"temp/") +5, strripos($str,"html") -1 );
?> 
</body>
</html>

 

that output is:

 

html = 19
html = index.html
html = index.html

 

what i'm trying to get is  getting the file name of any file one once with the *.html and the second time without the ".html", but without the '/lalala/temp/'. i'm not trying to cancel sub folders path and i want to it in the output.

let say i have the next two files:

'/lalala/temp/index.html' - one-> 'index.html' two->index

'/lalala/temp/news/index.html' - one-> 'news/index.html' two-> 'news/index'

 

i also tried in the last line of the php this line:

echo 'html = ' . substr($str, stripos($str,"temp/") +5, strripos($str,".") -1 );

as you all can see i'm looking here for the "." of the file but the output is the same:

 

html = 19
html = index.html
html = index.html

 

what am i doing wrong exactly and why my first command can find the 'html' text and the two other can't?


Viewing all articles
Browse latest Browse all 13200

Trending Articles