regexp how to avoid replace in tag attributes

Discussion in 'PHP' started by gilgalbiblewheel, Nov 6, 2008.

  1. #1
    <?php
    $strText = stripslashes(mysql_escape_string($row['text_data']));
    /*added later to replace string*/
    if(isset($_GET['searchChapWords'])){
    	$searchChapWords = $_GET['searchChapWords'];
    	$searchChapWordsArr = explode(" ", $searchChapWords);
    	//print_r($searchChapWordsArr);
    	# Where the good words go
    		$bigWords = array();
    		
    		# Cycle through each word
    		foreach ($searchChapWordsArr as $word) {
    		  # if it's 4 chars or less
    		  if (strlen($word) > 4 && !in_array($word,$bigWords)) {
    			# add it to the small words
    			$bigWords[] = $word;
    		  }
    		}
    	for($a=0; $a<count($bigWords);$a++){
    		$strText = preg_replace("/(".$bigWords[$a].")/i", "<span class=\"\" id=\"\" style=\" 						font-weight:bold;\">$1</span>", $strText);
    		//echo $searchChapWordsArr[$a]."<br />";
    	}
    }
    echo $strText."\n";
    /**/
    ?>
    PHP:
    I want to avoid the preg_replace of the tag attributes. I notice the word font-weight is split because it's sorting the word eight.

     
    gilgalbiblewheel, Nov 6, 2008 IP