0

Possible Duplicate:
PHP Regex extract a javascript variable

This is really probably just a simple string manipulation question that needs a good regex solution.

I have some javascript variables defined in an HTML page. I want to read the page in to PHP, identify the variable I want to change; and update it. The vars look like:

rsp.pageId = 'sports'

Just to be clear, my script will not know what the value is so in the example 'sports' could be anything; so it's a wildcard where the rest of the string is consistant. I don't know if it would be easier to wrap some comments around the var/value to get to it easier?

I appreciate the help. I'm playing with a DOM manipulation library so I thought about wrapping script tags around each variable and putting an ID on each. I think that would work but seems like the output would be a bit ridiculous.

2

1 Answer 1

0

do you need the spaces around the equals, if not here - preg_replace( "/rsp\.pageId='([a-zA-Z0-9])+'/", "rsp.pageId='blah'" ); if so try here - preg_replace( "/rsp\.pageId\s?=\s?'([a-zA-Z0-9])+'/", "rsp.pageId='blah'" );

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.