Jump to content

array processing


nagalenoj

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.