Search code examples
phpnotepad++notepad

How to add single quote at beginning and end of array variable in php using notepad++


I have delared variables like this. I have created more than 100 variables in every page.

<?php echo $rsedit[customer_name];  ?>
<?php echo $rsedit[address];  ?>
<?php echo $rsedit[city]; ?>
<?php echo $rsedit[pincode]; ?>
<?php echo $rsedit[contact_no]; ?>
<?php echo $rsedit[email_id]; ?>

I am searching and replacing in notepad++. But it takes long time.

I want following output:

<?php echo $rsedit['customer_name'];  ?>
<?php echo $rsedit['address'];  ?>
<?php echo $rsedit['city']; ?>
<?php echo $rsedit['pincode']; ?>
<?php echo $rsedit['contact_no']; ?>
<?php echo $rsedit['email_id']; ?>

Tell me the best solution for this to replace together.


Solution

  • I would use the following find and replace, in regex mode:

    Find:    <\?php echo \$(.*?)\[(.*?)\];\s*\?>
    Replace: <?php echo \$$1['$2']; ?>
    

    Demo