electronish Posted December 1, 2006 Share Posted December 1, 2006 what does this do ? [quote]preg_replace("/\s/","%20",$scanthis)[/quote]Well.. $scanthis is my present working directory .. what is /\s and %20 .. ? Link to comment https://forums.phpfreaks.com/topic/29075-very-basic-question-maybe-but-plz-help/ Share on other sites More sharing options...
Psycho Posted December 1, 2006 Share Posted December 1, 2006 preg_replace() is a function that does a "regular expression" search within the search text and replaces it with the replacement text. Format is like this:preg_replace ( search pattern, search replacement, subject )There are additional parameters that this function can take as well.Regular Expressions are a programatic way to do complex string functions. Trying to explain it is way beyond the scope of a forum post. Anyway, in the example you gave the search pattern is between two forward slash characters. the "\s" represents any white-space character such as a tab or space. Those are then replaced in the $scanthis variable with a "%20" - the URL escaped version of a space.So, if $scanthis equaled "This is a test", the output would be "This%20is%20a%20test" Link to comment https://forums.phpfreaks.com/topic/29075-very-basic-question-maybe-but-plz-help/#findComment-133264 Share on other sites More sharing options...
electronish Posted December 1, 2006 Author Share Posted December 1, 2006 Oh ok ./. got it So this means that %20 and \s means the same but for different platforms and just to make it compatible this step is performed . !! Cool .. Thanks very mch BTW ,. I am trying to make a PhP script which will get all the files and folder lists from a particular root folder and then will tell me which file is new. I am trying to make something like a file watcher . But since 3 days I am stuck just to list the files and folders and get them into arrays and database. :( Link to comment https://forums.phpfreaks.com/topic/29075-very-basic-question-maybe-but-plz-help/#findComment-133268 Share on other sites More sharing options...
Psycho Posted December 1, 2006 Share Posted December 1, 2006 [quote author=electronish link=topic=116950.msg476832#msg476832 date=1164957110]So this means that %20 and \s means the same but for different platforms and just to make it compatible this step is performed . !! Cool .. [/quote]That is NOT correct. A space and %20 are representations for the same thing, but \s is not a representation of a space. It is a regular expression metacharacther that MATCHES any white-space character - is is not a character itself. Link to comment https://forums.phpfreaks.com/topic/29075-very-basic-question-maybe-but-plz-help/#findComment-133493 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.