nagalenoj Posted December 22, 2008 Share Posted December 22, 2008 Dear friends, I have to process an array contents. The process is that, if the value is string, I have to quote the meta characters in the string(quotemeta) and enclose the string in a quotation. So, I have to check every array content. In perl, we have grep and map to do things like this. how to perform this in php? Link to comment https://forums.phpfreaks.com/topic/137981-array-processing/ Share on other sites More sharing options...
Lamez Posted December 22, 2008 Share Posted December 22, 2008 can you explain the function of grep? I found this: http://us.php.net/manual/en/function.preg-grep.php always take a look at: www.php.net, it is your best friend! Link to comment https://forums.phpfreaks.com/topic/137981-array-processing/#findComment-721167 Share on other sites More sharing options...
genericnumber1 Posted December 22, 2008 Share Posted December 22, 2008 I think you might consider array_walk() (or foreach as in perl) as a map replacement. PHP has a quotemeta (http://us.php.net/quotemeta), but I don't think it functions as a replacement for perl's. As the previous poster pointed out a preg_grep which functions similarly - but not exactly the same - as perl's grep functions... as I understand it at least. I'm not very experienced with perl. edit: <?php $testString = '#%test%@str_ing./3'; echo preg_replace('/([^A-Za-z_0-9])/', '\\\$1', $testString); should work similarly to perl's quotemeta. Link to comment https://forums.phpfreaks.com/topic/137981-array-processing/#findComment-721205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.