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 933773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:53:19+00:00 2026-05-15T20:53:19+00:00

I have some HTML that looks like this: $(document).ready(function(){ $(‘#cumulative-returns’).graph({ width: 400, height: 180,

  • 0

I have some HTML that looks like this:

    $(document).ready(function(){
        $('#cumulative-returns').graph({
            width: 400,
            height: 180,
            type: 'bar',
            x_label: 'Month',
            x_data: ['Jan','Feb','Mar','Apr'],
            y_label: 'Cumulative Return',
            y_data: ['5','10','15','20'],
            colors: ['666666', '000000', 'ff0000', '333366']
        });

        $('#new-returns').graph({
            width: 400,
            height: 180,
            type: 'bar',
            x_label: 'Month',
            x_data: ['Jan','Feb','Mar','Apr'],
            y_label: 'Cumulative Return',
            y_data: ['5','10','15','20'],
            colors: ['666666', '000000', 'ff0000', '333366']
        });
    });

What I need to do is replace x_data and y_data with new values using some nifty regex in PHP.

This is what I have come up with so far just to find the right graph but even that doesn’t work.

$graph = "cumulative-returns";
$start_tag = '$(\'#'.$graph.'\').graph({';
$end_tag = '});';
preg_match_all("/".preg_quote($start_tag)."(.+?)".preg_quote($end_tag)."/i", $html, $matches);
print_r($matches);

Any suggestions would be great!

*edit:

Please ignore the fact that its javascript, I just need to some regex to find the string between $('#cumulative-returns').graph({ and }); characters!

  • 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-05-15T20:53:19+00:00Added an answer on May 15, 2026 at 8:53 pm
    preg_match('/\$\(\'#cumulative-returns\'\)\.graph\({([^}]*)}\);/s',$input,$matches);
    

    After this, $matches[0] will have the values matched by the regex (including the surrounding text) and $matches[1] will have just the text between
    $('#cumulative-returns').graph({ and }); characters.

    Also, possibly more useful, would be:

    preg_match_all('/\$\(\'#[^\']*\'\)\.graph\({([^}]*)}\);/s',$input,$matches);
    

    After which matches[0][n] reflects the nth match (including surrounding text) and $matches[1][n] reflects the nth instance of text between $('#[any-text]').graph({ and });

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

Sidebar

Related Questions

I have some HTML that looks like this: <div> <div class=value> <a href=# class=clicker>Some
I have some HTML that looks like this: <div class=product> Content In Here <div
If I have some HTML that looks like this: <div id=text> This is some
I have some HTML that looks like this: <div class=MyClass></div> <div class=MyClass></div> <div class=MyClass></div>
We have some html that looks like this: <form id=MyUserControl runat=server method=post> <script language=javascript
I have an HTML Document that looks a bit like this, only is far
So I have some html that looks like the following: <div class='something unknown' id='something_unknown_1'>
I have some jQuery with an Ajax call that looks like this: $.ajax({ type:
I have HTML that looks like this: <form id=kinodForm> <input type=text name=element[5] value=krispy kreme
I currently have page-specific javascript files that look something like: $(document).ready(function () { namespace.home.list

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.