/    Sign up×
Community /Pin to ProfileBookmark

What Is Php Function And Regex To Replace This Specific Html Code ?

Howdy,

It’s like this ….
I have some html code in a $_SESSION.
One of the tags are:

““
</form>
““

Got to replace that code with:

““
</fieldset><fieldset>
““

How to do it with regex and preg_replace() as str_replace() not working ?
See here:

““
str_replace(‘</form>’,'</fieldset><fieldset>’,$_SESSION[‘html_form_builder’]);
““

Got to use preg_replace() instead. Correct ?
Big question is:
Will not str_replace() work if I try replacing symbols other than alpha-numerical chars ?

And, don’t close this thread saying other threads exist teaching how to replace html code with preg_replace() because those threads’ regex codes are no use to me as I am weak on regex. I actually need that specific regex to replace what you see above.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmApr 05.2022 — Is it a upper/lower case problem that seems to not make the change for you with strreplace? Have you tried the alternate version of function that ignores case?
Copy linkTweet thisAlerts:
@NogDogApr 05.2022 — I don't know why that str_replace() would not work for the stated use case, other than in your example you do not actually assign the result to anything. 🤷
<i>
</i>$ php -a
Interactive shell

php &gt; $text = "something something&lt;/form&gt;something something";
php &gt; $new_text = str_replace('&lt;/form&gt;', '&lt;/fieldset&gt;&lt;fieldset&gt;', $text);
php &gt; echo $new_text."n";
something something&lt;/fieldset&gt;&lt;fieldset&gt;something something
php &gt;
Copy linkTweet thisAlerts:
@ginerjmApr 05.2022 — HaH! Did Not Notice that! Of course!
Copy linkTweet thisAlerts:
@site-developerauthorApr 06.2022 — @NogDog#1643484,

Sorry! My mistake, I did not assign it to a variable. It's working now.
Copy linkTweet thisAlerts:
@site-developerauthorApr 06.2022 — @ginerjm#1643485

I did not notice it either! And again: OFCOURSE!
×

Success!

Help @site-developer 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.15,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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