All generations.

generate functionSun, 12 Feb 2023

write a joomla function to find the first h2 tag in the content and insert a html content before this tag

function put_stuff_before_h2_tag($content) { $html_tag = '<h2>'; $html_tag_at_position = strpos($content, $html_tag); $content_before_tag = substr($content, 0, $html_tag_at_position); $content_after_tag = substr($content, $html_tag_at_position); $content = $content_before_tag . '<div>Stuff I want to put in before the h2 tag</div>' . $content_after_tag; return $content; }

PHP
View
generate functionSun, 12 Feb 2023

write a laravel function to find the first h2 tag and insert a html content after this tag

public function insertAfterH2($content) { $doc = new \DOMDocument(); libxml_use_internal_errors(true); $doc->loadHTML($content); $xpath = new \DOMXPath($doc); $elements = $xpath->query('//h2'); if(!is_null($elements)) { foreach ($elements as $element) { $div = $doc->createElement('div', 'Inserted Text'); $element->parentNode->insertBefore($div, $element->nextSibling); } } return $doc->saveHTML(); }

PHP
View
generate functionSun, 12 Feb 2023

write a php function to find the first h2 tag inside a php value and insert a div after this tag

function insert_after_h2($content){ if (is_single()){ $h2_pos = strpos($content, '<h2>'); if (false !== $h2_pos) { $h2_pos +=4; $h2_end = strpos($content, '</h2>'); $h2_len = $h2_end - $h2_pos; $h2_text = substr($content, $h2_pos, $h2_len); $replacement = '<div>' . $h2_text . '</div>'; $content = substr_replace($content, $replacement, $h2_end, 0); } return $content; } } add_filter('the_content', 'insert_after_h2');

PHP
View
generate functionMon, 13 Feb 2023

rewrite this function to support multistore in PrestaShop: public function deleteorderbyid($id, $return = 0) { if (version_compare('1.7', _PS_VERSION_) <= 0) { $thisorder = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT id_cart FROM ' . _DB_PREFIX_ . 'orders WHERE id_order = ' . $id); if (isset($thisorder[0])) { $q = 'DELETE a,b FROM ' . _DB_PREFIX_ . 'order_return AS a LEFT JOIN ' . _DB_PREFIX_ . 'order_return_detail AS b ON a.id_order_return = b.id_order_return WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } // deleting order_slip $q = 'DELETE a,b FROM ' . _DB_PREFIX_ . 'order_slip AS a LEFT JOIN ' . _DB_PREFIX_ . 'order_slip_detail AS b ON a.id_order_slip = b.id_order_slip WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'cart_product WHERE id_cart="' . $thisorder[0]['id_cart'] . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_history WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_detail_tax WHERE id_order_detail IN (SELECT id_order_detail FROM ' . _DB_PREFIX_ . 'order_detail WHERE id_order ="' . $id . '")'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_detail WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_payment WHERE order_reference IN (SELECT reference FROM ' . _DB_PREFIX_ . 'orders WHERE id_order="' . $id . '")'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'orders WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_carrier WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_invoice_tax WHERE id_order_invoice IN (SELECT id_order_invoice FROM ' . _DB_PREFIX_ . 'order_invoice WHERE id_order="' . $id . '")'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_invoice WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_invoice_payment WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } $q = 'DELETE FROM ' . _DB_PREFIX_ . 'order_cart_rule WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } if (empty($this->errorlog)) { if ($return == 1) { $this->context->controller->confirmations[] = $this->l('Order deleted'); } else { return $this->l('Order deleted'); } } else { if ($return == 1) { $this->context->controller->errors[] = $this->l('Something wrong'); } else { return $this->l('Something wrong'); } } } else { if ($return == 1) { $this->context->controller->errors[] = $this->l('Order doesnt exists'); } else { return $this->l('Order doesnt exists'); } } } }

function deleteorder($id) { if (version_compare('1.7', _PS_VERSION_) <= 0) { $thisorder = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT id_cart FROM ' . _DB_PREFIX_ . 'orders WHERE id_order = ' . $id); if (isset($thisorder[0])) { $q = 'DELETE a,b FROM ' . _DB_PREFIX_ . 'order_return AS a LEFT JOIN ' . _DB_PREFIX_ . 'order_return_detail AS b ON a.id_order_return = b.id_order_return WHERE id_order="' . $id . '"'; if (!Db::getInstance()->Execute($q)) { $this->errorlog = $this->l('ERROR'); } // deleting order_slip $q = 'DELETE a,b FROM ' . _DB_PREFIX_ . 'order_

PHP
View

Questions about programming?Chat with your personal AI assistant