{"id":14054,"date":"2022-10-06T08:50:02","date_gmt":"2022-10-06T03:20:02","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/"},"modified":"2022-10-06T08:50:02","modified_gmt":"2022-10-06T03:20:02","slug":"solved-probleme-adding-txt-and-links-in-preg_match","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/","title":{"rendered":"[Solved] probleme adding Txt and Links in preg_match()"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-189278\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"189278\" data-parentid=\"189117\" data-score=\"-2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"suggestedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Finally a solution provide by @Rizier123<\/p>\n<pre><code>if(!preg_match(\"https:\/\/wordpress.stackexchange.com\/\" . preg_quote($citation_string, \"https:\/\/wordpress.stackexchange.com\/\") . \"https:\/\/wordpress.stackexchange.com\/\", $footer_contents))\n<\/code><\/pre>\n<p>@Rizier123 say : The problem are the slashes in your pattern, just use <strong>preg_quote()<\/strong> to escape them, e.g.<\/p>\n<p>so the code will be like this :<\/p>\n<pre><code>add_action('template_redirect', 'foobar_explode_if_no_citation');\nfunction foobar_explode_if_no_citation(){\n\n#Get the absolute server path to footer.php\n$footer_path = locate_template('footer.php');\n\n#Store the footer file contents in a var\n$footer_contents = file_get_contents($footer_path);\n\n#The required string\n$citation_string = 'Designed by Foo Bar &lt;a href=\"http:\/\/YourLink.com\"&gt;anchor&lt;\/a&gt;';\n\n#Set off the nuclear bomb if there is an egregious offense\nif(!preg_match(\"https:\/\/wordpress.stackexchange.com\/\" . preg_quote($citation_string, \"https:\/\/wordpress.stackexchange.com\/\") . \"https:\/\/wordpress.stackexchange.com\/\", $footer_contents))\n    exit('All your websitez are belong to me. Make sure this string \"Designed by Foo Bar\" is included in footer.php');\n}\n<\/code><\/pre>\n<p><strong>? Who will work with this code ?<\/strong><\/p>\n<p>coders who <strong>worked days and night<\/strong> to provide great content, and just putting their citation words or link as a copyright..and dont want a user of the script <strong>remove it or replace it<\/strong> with his own <strong>without permission<\/strong>&#8230; <\/p>\n<p><strong>it&#8217;s just a simple way to respect the copyright! respect coders.<\/strong><\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">5<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved probleme adding Txt and Links in preg_match() <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Finally a solution provide by @Rizier123 if(!preg_match(&#8220;https:\/\/wordpress.stackexchange.com\/&#8221; . preg_quote($citation_string, &#8220;https:\/\/wordpress.stackexchange.com\/&#8221;) . &#8220;https:\/\/wordpress.stackexchange.com\/&#8221;, $footer_contents)) @Rizier123 say : The problem are the slashes in your pattern, just use preg_quote() to escape them, e.g. so the code will be like this : add_action(&#8216;template_redirect&#8217;, &#8216;foobar_explode_if_no_citation&#8217;); function foobar_explode_if_no_citation(){ #Get the absolute server path to footer.php $footer_path = locate_template(&#8216;footer.php&#8217;); #Store &#8230; <a title=\"[Solved] probleme adding Txt and Links in preg_match()\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/\" aria-label=\"More on [Solved] probleme adding Txt and Links in preg_match()\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[627],"tags":[339],"class_list":["post-14054","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] probleme adding Txt and Links in preg_match() - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] probleme adding Txt and Links in preg_match() - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Finally a solution provide by @Rizier123 if(!preg_match(&quot;https:\/\/wordpress.stackexchange.com\/&quot; . preg_quote($citation_string, &quot;https:\/\/wordpress.stackexchange.com\/&quot;) . &quot;https:\/\/wordpress.stackexchange.com\/&quot;, $footer_contents)) @Rizier123 say : The problem are the slashes in your pattern, just use preg_quote() to escape them, e.g. so the code will be like this : add_action(&#039;template_redirect&#039;, &#039;foobar_explode_if_no_citation&#039;); function foobar_explode_if_no_citation(){ #Get the absolute server path to footer.php $footer_path = locate_template(&#039;footer.php&#039;); #Store ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-06T03:20:02+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-probleme-adding-txt-and-links-in-preg_match\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-probleme-adding-txt-and-links-in-preg_match\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] probleme adding Txt and Links in preg_match()\",\"datePublished\":\"2022-10-06T03:20:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-probleme-adding-txt-and-links-in-preg_match\\\/\"},\"wordCount\":109,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"php\"],\"articleSection\":[\"WordPress\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-probleme-adding-txt-and-links-in-preg_match\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-probleme-adding-txt-and-links-in-preg_match\\\/\",\"name\":\"[Solved] probleme adding Txt and Links in preg_match() - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2022-10-06T03:20:02+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-probleme-adding-txt-and-links-in-preg_match\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-probleme-adding-txt-and-links-in-preg_match\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-probleme-adding-txt-and-links-in-preg_match\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] probleme adding Txt and Links in preg_match()\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\\\/\\\/jassweb.com\"],\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/author\\\/jaspritsinghghumangmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] probleme adding Txt and Links in preg_match() - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] probleme adding Txt and Links in preg_match() - JassWeb","og_description":"[ad_1] Finally a solution provide by @Rizier123 if(!preg_match(\"https:\/\/wordpress.stackexchange.com\/\" . preg_quote($citation_string, \"https:\/\/wordpress.stackexchange.com\/\") . \"https:\/\/wordpress.stackexchange.com\/\", $footer_contents)) @Rizier123 say : The problem are the slashes in your pattern, just use preg_quote() to escape them, e.g. so the code will be like this : add_action('template_redirect', 'foobar_explode_if_no_citation'); function foobar_explode_if_no_citation(){ #Get the absolute server path to footer.php $footer_path = locate_template('footer.php'); #Store ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/","og_site_name":"JassWeb","article_published_time":"2022-10-06T03:20:02+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] probleme adding Txt and Links in preg_match()","datePublished":"2022-10-06T03:20:02+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/"},"wordCount":109,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["php"],"articleSection":["WordPress"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/","url":"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/","name":"[Solved] probleme adding Txt and Links in preg_match() - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-06T03:20:02+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-probleme-adding-txt-and-links-in-preg_match\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] probleme adding Txt and Links in preg_match()"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/14054","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=14054"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/14054\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=14054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=14054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=14054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}