Avatar of jeremyBass26
jeremyBass26Flag for United States of America

asked on 

regex to replace all trems but what is wraped in a no replace phase

Hello, I want to skip wors in this


 
<ul>
  <li><a href="#pci">What is PCI?</a></li>
  <li><a href="#dss">What is the 'PCI DSS'?</a></li>
  <li><a href="#apply">To whom does PCI apply?</a></li>
  <li><a href="#refuse">What if a Merchant refuses to cooperate?</a></li>
  <li><a href="#okay">What does a Merchant have to do in order to satisfy the PCI requirements?</a></li>
  <li><a href="#saq1">What is the 'Self-Assessment Questionnaire'?</a></li>
  <li><a href="#saq2">What is the 'SAQ'?</a></li>
  <li><a href="#compliance">What is meant by 'Compliance'?</a></li>
  <li><a href="#validation">What is meant by 'Validation'?</a></li>
  <li><a href="#levels">How are the different Merchant Levels defined?</a></li>
  <li><a href="#remediation">What is meant by 'Remediation'?</a></li>
  <li><a href="#government">Is PCI a government program? Is it a law?</a></li>
  <li><a href="#panoptic">Are Merchants required to use the tools provided through this web-site to fix any compliance problems?</a></li>
  <li><a href="#Internet">If a merchant does not have Internet access what options do they have to complete the SAQ forms?</a></li>
  <li><a href="#printRemed">How do I print my Fix-It Plan?</a></li>
  <li><a href="#glossary">Glossary of Technical Terms</a></li>
  <li><a href="#submitQuestion">Submit a Question</a></li>
</ul>

Open in new window



that I was reaplacing the key words with

$content = preg_replace("|(?!<[^<>]*?)(?<![?./&])\b$term\b(?!:)(?![^<>]*?>)|imsU","<span class=\"gloss\"><strong>$term_link</strong></span>" , $content);

Open in new window


which works great to pick up the words and do the replace as needed.. but I need to skip areas so I added this

 
<ul>
<!--glossover-start-->  <li><a href="#pci">What is PCI?</a></li>  <li><a href="#dss">What is the 'PCI DSS'?</a></li><!--glossover-end-->
  <li><a href="#apply">To whom does PCI apply?</a></li>
  <li><a href="#refuse">What if a Merchant refuses to cooperate?</a></li>
  <li><a href="#okay">What does a Merchant have to do in order to satisfy the PCI requirements?</a></li>
  <li><a href="#saq1">What is the 'Self-Assessment Questionnaire'?</a></li>
  <li><a href="#saq2">What is the 'SAQ'?</a></li>
  <li><a href="#compliance">What is meant by 'Compliance'?</a></li>
  <li><a href="#validation">What is meant by 'Validation'?</a></li>
  <li><a href="#levels">How are the different Merchant Levels defined?</a></li>
  <li><a href="#remediation">What is meant by 'Remediation'?</a></li>
  <li><a href="#government">Is PCI a government program? Is it a law?</a></li>
  <li><a href="#panoptic">Are Merchants required to use the tools provided through this web-site to fix any compliance problems?</a></li>
  <li><a href="#Internet">If a merchant does not have Internet access what options do they have to complete the SAQ forms?</a></li>
  <li><a href="#printRemed">How do I print my Fix-It Plan?</a></li>
  <li><a href="#glossary">Glossary of Technical Terms</a></li>
  <li><a href="#submitQuestion">Submit a Question</a></li>
</ul>

Open in new window



where the key work PCI (which would have been replaced twice) should have been skiped with the updated patteren of


 
$content = preg_replace("|(?<![^glossover\-start])(?!<[^<>]*?)(?<![?./&])\b$term\b(?!:)(?![^<>]*?>)(?![^glossover\-end])|imsU","<span class=\"gloss\"><strong>$term_link</strong></span>" , $content);

Open in new window



but it's not working.. any ideas on how to fix it?  Thanks.
Regular ExpressionsPHPWeb Development

Avatar of undefined
Last Comment
Ray Paseur
SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of jeremyBass26
jeremyBass26
Flag of United States of America image

ASKER

@Ray you got it backward  so.. from  
<ul>
<!--glossover-start-->  <li><a href="#pci">What is PCI?</a></li>  <li><a href="#dss">What is the 'PCI DSS'?</a></li><!--glossover-end-->
  <li><a href="#apply">To whom does PCI apply?</a></li>
  <li><a href="#refuse">What if a Merchant refuses to cooperate?</a></li>
  <li><a href="#okay">What does a Merchant have to do in order to satisfy the PCI requirements?</a></li>
  <li><a href="#saq1">What is the 'Self-Assessment Questionnaire'?</a></li>
  <li><a href="#saq2">What is the 'SAQ'?</a></li>
  <li><a href="#compliance">What is meant by 'Compliance'?</a></li>
  <li><a href="#validation">What is meant by 'Validation'?</a></li>
  <li><a href="#levels">How are the different Merchant Levels defined?</a></li>
  <li><a href="#remediation">What is meant by 'Remediation'?</a></li>
  <li><a href="#government">Is PCI a government program? Is it a law?</a></li>
  <li><a href="#panoptic">Are Merchants required to use the tools provided through this web-site to fix any compliance problems?</a></li>
  <li><a href="#Internet">If a merchant does not have Internet access what options do they have to complete the SAQ forms?</a></li>
  <li><a href="#printRemed">How do I print my Fix-It Plan?</a></li>
  <li><a href="#glossary">Glossary of Technical Terms</a></li>
  <li><a href="#submitQuestion">Submit a Question</a></li>
</ul>

Open in new window


where I look to replace PCI  with

<span class="gloss"><strong>$term_link</strong></span>

which would give me

<ul>
<!--glossover-start-->  <li><a href="#pci">What is PCI?</a></li>  <li><a href="#dss">What is the 'PCI DSS'?</a></li><!--glossover-end-->
  <li><a href="#apply">To whom does <span class="gloss"><strong>PCI</strong></span> apply?</a></li>
  <li><a href="#refuse">What if a Merchant refuses to cooperate?</a></li>
  <li><a href="#okay">What does a Merchant have to do in order to satisfy the <span class="gloss"><strong>PCI</strong></span> requirements?</a></li>
  <li><a href="#saq1">What is the 'Self-Assessment Questionnaire'?</a></li>
  <li><a href="#saq2">What is the 'SAQ'?</a></li>
  <li><a href="#compliance">What is meant by 'Compliance'?</a></li>
  <li><a href="#validation">What is meant by 'Validation'?</a></li>
  <li><a href="#levels">How are the different Merchant Levels defined?</a></li>
  <li><a href="#remediation">What is meant by 'Remediation'?</a></li>
  <li><a href="#government">Is <span class="gloss"><strong>PCI</strong></span> a government program? Is it a law?</a></li>
  <li><a href="#panoptic">Are Merchants required to use the tools provided through this web-site to fix any compliance problems?</a></li>
  <li><a href="#Internet">If a merchant does not have Internet access what options do they have to complete the SAQ forms?</a></li>
  <li><a href="#printRemed">How do I print my Fix-It Plan?</a></li>
  <li><a href="#glossary">Glossary of Technical Terms</a></li>
  <li><a href="#submitQuestion">Submit a Question</a></li>
</ul>

Open in new window


So that anyything in the <!--glossover-start--> <!--glossover-end--> area doesn't get replaced.


@kaufmed isn't [^glossover\-start] saying any characters except those listed?  ie: [^notWantedPhrase]



Please let me know if there is any thing else I can add to clear up the need.  thank you.. Cheers -Jeremy
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of jeremyBass26
jeremyBass26
Flag of United States of America image

ASKER

So here is what I tried with
<?php
//if (!isset(cmsms())) exit;
global $CMS_ADMIN_PAGE;
//print($CMS_ADMIN_PAGE.' admin');

if($CMS_ADMIN_PAGE!=1){
	if (substr($_GET['page'], 0,8)!="glossary"){
		$content=$params["content"];
		global $gCms;
		$config = $gCms->GetConfig();
		$tmp_file=$config['root_path'].'/tmp//templates_c/gloss.tmp';
				if(!file_exists($tmp_file)){
					$db = $gCms->db;
					$query = 'SELECT * FROM '.cms_db_prefix().'module_glossary_term';
					$result=$db->Execute($query,array());
					$resultsarray=array();
					while ($result && !$result->EOF){
						$term=$result->fields['term'];
						$returnid='69';
						$id='asdga';
						$def = $result->fields['definition'];
						$prettyurl = 'glossary/'.$term.'/'.$returnid;
						$term_link = $this->CreateFrontendLink($id, 'show', $returnid, $term,array('tid'=>$result->fields['term_id']), '', false, false, 'rel="'.$def.'"', false,$prettyurl);
						$resultsarray[]=array('term'=>$term,'term_link'=>$term_link);
						$result->MoveNext();
					}
					$fn = $tmp_file;
					$fp = fopen($fn, "w");
					if (!$fp) {
						return 0;
					}
					fwrite($fp, serialize($resultsarray));
					fclose($fp);
					$data=file_get_contents($tmp_file);
				}else{
					$data=file_get_contents($tmp_file);
				}
				//debug_display('$data---->'.$data);
			$result=unserialize($data);
		
			foreach($result as $key => $item){
				$term=$item['term'];
				$term_link=$item['term_link'];
				//$pattern = '/()'.$term.'/';
				//$replacement='<span class="gloss"><strong>'.$term_link .'</strong></span>';
				//debug_display('$replacement---->'.$replacement);
				//$content = preg_replace($pattern, $replacement, $content); 
				
				
				
				
				
				/*$content = preg_replace("|(?<![^glossover\-start])(?!<[^<>]*?)(?<![?./&])\b$term\b(?!:)(?![^<>]*?>)(?![^glossover\-end])|imsU","<span class=\"gloss\"><strong>$term_link</strong></span>" , $content);*/
	$gloss = '#<!--glossover-start-->.*?<!--glossover-end-->#';		// Pattern for a glossy section
	$term_link = "<span class=\"gloss\"><strong>$term_link</strong></span>";
	
	if (preg_match_all($gloss, $content, $glossed))	{			// Find all glossy sections
		$content = preg_replace($gloss, $temp_replace, $content);	// Replace glossy sections with temporary placeholder
		$content = str_replace($term, $term_link, $content);		// Replace non-glossy PCI occurrences

		preg_match_all("/$temp_replace/", $content, $temps);		// Find all placeholders
		$content = str_replace($temps[0], $glossed[0], $content);	// Replace placeholders with original values.
	}

	//echo $content;

				  // Acronyms wrapped in dollar signs will just be unwrapped: 
				  // So: $AOL$ will become AOL, without the <acronym title="America Online">AOL</acronym> 
      			$content = preg_replace("|[$]<span class=\"gloss\"><strong>$term_link</strong></span>[$]|imsU" , "$term" , $content);
				
				
				
			}
			$params["content"]=trim($content);
	}
}

Open in new window


where $term included PCI with its it's link in $term_link .  


Also I thought preg_replace what fast then preg_match_all as there is not an array created and such, or am I off on that?

$content = preg_replace("|(?!<[^<>]*?)(?<![?./&])\b$term\b(?!:)(?![^<>]*?>)|imsU","<span class=\"gloss\"><strong>$term_link</strong></span>" , $content);

That does match the $term, so I thought I just needed to addjust the grouping and put the pattern be tween a Not followed by and Not following  group. .. or that was the thought :)

tk for the help.. Cheers -Jeremy
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
ASKER CERTIFIED SOLUTION
Avatar of jeremyBass26
jeremyBass26
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of jeremyBass26
jeremyBass26
Flag of United States of America image

ASKER

it's the working anwser build of the rest.  tk all for the help
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Wow!  Haven't seen you in a while!  Welcome back, ~Ray
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo