linuxfreakphp Posted December 6, 2013 Share Posted December 6, 2013 (edited) 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 = 19html = index.htmlhtml = 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 = 19html = index.htmlhtml = 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 December 6, 2013 by linuxfreakphp Quote Link to comment https://forums.phpfreaks.com/topic/284573-problem-with-printing-only-part-of-changing-string/ Share on other sites More sharing options...
requinix Posted December 6, 2013 Share Posted December 6, 2013 For the filename, with or without extension, basename. For the path relative to /lalala/temp, substr($str, strlen("/lalala/temp/")) Quote Link to comment https://forums.phpfreaks.com/topic/284573-problem-with-printing-only-part-of-changing-string/#findComment-1461459 Share on other sites More sharing options...
linuxfreakphp Posted December 6, 2013 Author Share Posted December 6, 2013 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) Quote Link to comment https://forums.phpfreaks.com/topic/284573-problem-with-printing-only-part-of-changing-string/#findComment-1461462 Share on other sites More sharing options...
requinix Posted December 6, 2013 Share Posted December 6, 2013 Ah, no extension. What I posted + dirname + basename(). Quote Link to comment https://forums.phpfreaks.com/topic/284573-problem-with-printing-only-part-of-changing-string/#findComment-1461463 Share on other sites More sharing options...
linuxfreakphp Posted December 6, 2013 Author Share Posted December 6, 2013 (edited) 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 December 6, 2013 by linuxfreakphp Quote Link to comment https://forums.phpfreaks.com/topic/284573-problem-with-printing-only-part-of-changing-string/#findComment-1461468 Share on other sites More sharing options...
requinix Posted December 6, 2013 Share Posted December 6, 2013 Don't worry about resources. Quote Link to comment https://forums.phpfreaks.com/topic/284573-problem-with-printing-only-part-of-changing-string/#findComment-1461470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.