0

Can someone make a regular expression for Notepad++ to replace this:

mysql_fetch_array($result)

by this:

$result->fetch_array()

The variable name could also have an other name, for example:

mysql_fetch_array($result_2)

should also be replaced by

$result_2->fetch_array()

Thanks!

2
  • 3
    why not replace them manually? you can simply use notepad++ and search (Ctrl + Shift + f) search in files and then change one by one, because this is critical do not depend on regex Commented Jul 19, 2013 at 22:51
  • Why is that so important, I mean, it is ok if I replace them with that? Commented Jul 19, 2013 at 22:53

1 Answer 1

0

Regarding to my comment, I am still suggesting to replace them manually, however, this code might help you also:

<?php
$string = 'mysql_fetch_array($result_2)';

echo preg_replace('#mysql_fetch_array\(([^\)]+)\)#', '\\1->fetch_array()', $string);
echo preg_replace('#mysql_fetch_array\((.*?)\)#', '\\1->fetch_array()', $string);
?>

output:

$result_2->fetch_array()
$result_2->fetch_array()
3
  • Thanks for the help! But can you tell me why it is better to replace them manually? I mean, if I replace the code, it will work, or is that wrong? Commented Jul 19, 2013 at 22:59
  • 1
    because sometimes regex might fail, this because of unexpected error or charactor when matching, don't you have time to review your code and improve it? Commented Jul 19, 2013 at 23:03
  • I don't have much time, but my website is also very complex with thousands of 'mysql_fetch_array's'. But I will think about it. Another thing: could you also make a regular expression for Notepad++? Commented Jul 19, 2013 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.