Jump to content

Recommended Posts

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?

Edited by linuxfreakphp

For the filename, with or without extension, basename.

 

For the path relative to /lalala/temp,

substr($str, strlen("/lalala/temp/"))

thanks for the answer  but is what is taking less resources strlen or strripos/stripos in this case?

 

it is still don't answer my question case number two:

 

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

'/lalala/temp/news/index.html' - one-> 'news/index.html' two-> 'news/index' (case number two)

What I posted + dirname + basename().

 

thanks, i didn't know this functions are exist and that why i turn to stripos.

what about my question about the resources of every function? can you answer it?

Edited by linuxfreakphp
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.