Hello,
Given a string like <form method="post" action="xyz.com"> I have to change it to <form method="post" action="myurl.com">. Could someone help me with this please?
I think its something like

preg_replace("/(<form.*action=")xyz.com(*.>;)/", "$1myurl.com$2")

but its not working. Kindly help.

Hello,
Given a string like <form method="post" action="xyz.com"> I have to change it to <form method="post" action="myurl.com">. Could someone help me with this please?
I think its something like

preg_replace("/(<form.*action=")xyz.com(*.>;)/", "$1myurl.com$2")

but its not working. Kindly help.

there's a quote after action= which is breaking the first string argument and it's needlessly complex.

Try

$var='<form method="post" action="xyz.com">';
echo preg_replace("/action=\"xyz.com\"/", "action=\"myurl.com\"", $var);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.