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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.