-1
$content = preg_replace('%^\s*<ul>(.+)</ul>\s*$%sim', '\1', $menulist); 

What is the meaning of first argument in the above function?

If I print $content I get the following categories as below:

Business

Accounting

Accounting For Leasing

Acqusition Disposition

Balance Sheet And Cash Flows

and so on....

Now Business is main category and Accounting is its subcategoy. Now I want to store them in array. How can I do that?

fawad
  • 1,183
  • 9
  • 29
  • 48

3 Answers3

0

http://php.net/manual/en/function.preg-replace.php

from above:

The pattern to search for. It can be either a string or an array with strings.

stecb
  • 13,412
  • 2
  • 47
  • 66
0

The first argument is regular expression, it's a sort of language for string matching. It's widely used in the programming world and supported by most languages like PHP, JavaScript, Python and many more. You can find out more about regular expression here: http://en.wikipedia.org/wiki/Regular_expression and read up one the function preg_replace() here: http://php.net/manual/en/function.preg-replace.php

Karl Laurentius Roos
  • 4,110
  • 1
  • 31
  • 38
  • You totally changed your question, you asked what the first argument for `preg_replace()` was and an explanation for it. Now you asking something totally else. – Karl Laurentius Roos May 18 '11 at 11:05
0

It Performs a regular expression search against a content and replace the matched string with the given replace string.

<?php
$string = 'April 15, 2003';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = '${1}1,$3';
echo preg_replace($pattern, $replacement, $string);
?>

The above example will output:

April1,2003

Read more about this on http://php.net/manual/en/function.preg-replace.php

Vijay
  • 5,063
  • 9
  • 48
  • 85
  • If I print $content I get the following categories as below: Business Accounting Accounting For Leasing Acqusition Disposition Balance Sheet And Cash Flows and so on.... – fawad May 18 '11 at 09:12