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
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
Share on other sites

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.