Jump to content

Removing some characters from string


RChilton

Recommended Posts

I have a field being imported from a .txt file.  Each field has multiple ^ characters which need to be removed then each different sku in the field is separated by | to indicate a new sku.  Some of the  sku's  have hyphens example 12345-6.  As the code is written these skus do not show up because it is stripping the hypen out too and then it is an ureconizable sku.  Currently the code is:

 

$related=preg_replace("/[^a-zA-Z0-9|]/", "", $product['related']);

$relatedrestricted = array('hospitalitymirrors', 'hospitalityaccessories', 'hospitalityfurniture', 'hospitalitylighting');
if (!empty($related) && !in_array($cat, $relatedrestricted)){
    $relatedItems = explode("|", $related);
      echo ("<tr>
              <td colspan=\"2\">
                  <h2>Related Products</h2>
                  <ul id=\"relatedItems\">
                  ");
      foreach($relatedItems as $relatedItem) {
          if (isProduct($link, $relatedItem)) {
            echo ("<li>
                      <a href=\"products.php?prod=$relatedItem&related=true\">
                        <img src=\"images/productimages/thumb_$relatedItem.jpg\" alt=\"View " . getName($relatedItem) . "\"/><br />
                        $relatedItem<br />
                        " .  getName($relatedItem) . "
                    </a>
                   </li>
                  ");
          }
      }

 

 

Link to comment
https://forums.phpfreaks.com/topic/286172-removing-some-characters-from-string/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.