I am editing some Interspire Email code. Currently the program goes through the HTML of the email before sending, and looks for 'a href' code, to replace the links. I want it to also go through and get form action="" and replace the urls in them (it does not currently). I think I can use the regex from this stack post:
PHP - Extract form action url from mailchimp subscribe form code using regex
but I'm having some difficulty wrapping my head around how to handle the arrays. The current code that just does the 'a href=' is below:
preg_match_all('%<a.+(href\s*=\s*(["\']?[^>"\']+?))\s*.+>%isU', $this->body['h'], $matches);
$links_to_replace = $matches[2];
$link_locations = $matches[1];
arsort($link_locations);
reset($links_to_replace);
reset($link_locations);
foreach ($link_locations as $tlinkid => $url) {
// so we know whether we need to put quotes around the replaced url or not.
$singles = false;
$doubles = false;
// make sure the quotes are matched up.
// ie there is either 2 singles or 2 doubles.
$quote_check = substr_count($url, "'");
if (($quote_check % 2) != 0) {
...
I know (or I think I know), that I need to replace preg_match_all with:
preg_match_all(array('%<a.+(href\s*=\s*(["\']?[^>"\']+?))\s*.+>%isU', '|form action="([^"]*?)" method="post" id="formid"|i'), $this->body['h'], $matches);
but then how are the '$matches' handled?
$links_to_replace = $matches[2];
$link_locations = $matches[1];
does not still hold true does it? Is it possible to do what I'm thinking? Or would I need to write another function just to handle the 'forms action=' seperate from the 'a href'