/    Sign up×
Community /Pin to ProfileBookmark

Replace php tags with #

Hi folks,
I have got a textarea and some html/php code in it. What I want to do is replace php tags with # symbol. Here’s what I got:

[CODE]
sourceCode.replace(/<?php .* ?>/g, “#”);
[/CODE]

but if code textarea content looks like this
[b]<a href=”<?php echo $link; ?>” title=”<?php echo $title; ?>”><?php echo $link; ?></a>[/b]
the result is following
[b]<a href=”#</a>[/b]
while it should look like this
[b]<a href=”#” title=”#”>#</a>[/b]

How to correct this issue?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991May 13.2009 — You have to specify what is allowed between the php tags, becuase it will replace from the first to the last. This won't always work, because it will stop at the first >, if you've HTML included, that could potentially be a problem.
/&lt;?php [^&gt;]+ ?&gt;/g
Copy linkTweet thisAlerts:
@ninkyauthorMay 13.2009 — It doesn't work in 100%, but thanks for the clue.
Copy linkTweet thisAlerts:
@ZeroKilledMay 13.2009 — try the following regular expression. the problem was greedy quantifier.
/&lt;?(.|n|r)+??&gt;/
Copy linkTweet thisAlerts:
@ninkyauthorMay 14.2009 — Amazing, thank you very much!
Copy linkTweet thisAlerts:
@ninkyauthorMay 14.2009 — Hmm, what about unhide() function?

If I hide php tags and then modify some html, I click "show php tags" and it returns me php tags but with unmodified html. Do I need to store php tags in some special array or var, in order to unhide them?
Copy linkTweet thisAlerts:
@felgallMay 14.2009 — How are you planning for the JavaScript to even see the PHP tags. The usual order for processing is that the PHP runs first generating HTML and the JavaScript runs against the HTML that the PHP generated.
Copy linkTweet thisAlerts:
@ninkyauthorMay 15.2009 — We are talking about CONTENT OF A TEXTAREA, there is displayed PHP+HTML...
×

Success!

Help @ninky spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...