Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8058635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:25:19+00:00 2026-06-05T09:25:19+00:00

Possible Duplicate: Parse PHP code to extract function names? I’m working on a script

  • 0

Possible Duplicate:
Parse PHP code to extract function names?

I’m working on a script to read my PHP files and get all the functions as a return.

I’m using preg_split() to split my file into an array of functions.

I’m having trouble writing the pattern to get all the functions returned (faced issue when the function’s name contains the word ‘function’. I’m open to any other solutions / advice.

Expected output:

array (
  0 => 'function write{$oneparam, $two, $three){return $two}',
  1 => 'function read{$oneparam, $two, $tthree){returne $awesome}',
  2 => 'function edit{$oneparam, $two, $three){return $two},
  3 => 'function delete{$oneparam, $two, $three){return $two}',
  4 => 'function lastfunction{$oneparam, $two, $three){return $two}'
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:25:21+00:00Added an answer on June 5, 2026 at 9:25 am

    You can try something like this to capture just the names / declarations:

    #(function\s+\w+\(.*?\)#s
    

    Or this to include the body of the function (assuming they’re on a single line like in your example):

    #(function\s+\w+\(.*?\)\s*{.*?})#s
    

    It works for all of your test cases, and without any sample input or more details, I can’t elaborate further.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: A PHP regex to extract php functions from code files I have
Possible Duplicate: How to parse HTML with PHP? Get MySQL database output via PHP
Possible Duplicate: Access array returned by a function in php The code: $cnt =
Possible Duplicate: Best methods to parse HTML with PHP I wish to get the
Possible Duplicate: How to parse and process HTML with PHP? i get page with
Possible Duplicate: How to parse and process HTML/XML with PHP? I want to grab
Possible Duplicate: How to parse and process HTML with PHP? Here is what I'm
Possible Duplicate: Parse XML with Namespace using SimpleXML PHP SimpleXML Namespace Problem <?php header(Content-Type:
Possible Duplicate: How to parse and process HTML with PHP? $content = <p>This is
Possible Duplicate: How to implement a web scraper in PHP? How to parse and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.