Search Hi-Light

2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 31, 2015   (RSS)

By gregThomas - March 31, 2015

Hi Perch,

You can do that using the following method:

<!-- show errors -->
    <?php if ($searchDetails['invalidPageNum']): ?>
      Results page '<?php echo $searchDetails['page']?>' not found, <a href="<?php echo $searchDetails['firstPageLink'] ?>">start over &gt;&gt;</a>.<br/>
    <?php elseif ($searchOptions['keywords'] && $searchDetails['noRecordsFound']): ?>
      No records matched search query!<br/><br/>
    <?php elseif ($searchOptions['keywords'] == ""): ?>
      Enter a keyword to search.<br/><br/>
    <?php endif ?>

<!-- STEP2: Display Record List -->
  <?php foreach ($searchRows as $record): ?>
      $record['_title'] = str_ireplace(@$_REQUEST['q'], "<i>" . @ucfirst($_REQUEST['q']) . "</i>", $record['_title']);
      $record['_summary'] = str_ireplace(@$_REQUEST['q'], "<i>" . @ucfirst($_REQUEST['q']) . "</i>", $record['_summary']);
    <a href="/<?php echo $record['field1'] ?>"><?php echo $record['_title'] ?></a><br/>
     <?php if ($record['_summary']): ?>
       <?php echo $record['_summary']); ?><br/>
      <?php else: ?>
        No description available for page.<br/>
      <?php endif ?>
     <a href="/<?php echo $record['field1'] ?>" style="color: #008000"><?php echo $record['field1'] ?></a><br/><br/>
  <?php endforeach ?>
  <!-- /STEP2: Display Record List -->

So the code above searches the returned title and summary and replaces the search term with itself, but with italic tags. You can read about the str_ireplce function here:



Greg Thomas

PHP Programmer -