I need some advice on this file I am working on. What it is for is my OSC cart. It's this bizrate feed and while everything works the description is to long for bizrate to accept the feed so I need to limit the amount of characters it outputs. It was advise that I use the php sprintf function but I don't see how that function will limit the number of characters the file outputs. So could I get some suggestions or guidance on how to to this.

Here is the a portion of the code I am working with

	preg_replace($_strip_search, $strip_replace, strip_tags( str_replace(">", "> ", $row->description) ) ) . "\t" .

Here is how the code is use in whole within the file. This isn't the entire file just part of the code where the above code is used in the file.

	$output .=
	$catIndex[$row->prodCatID] . "\t" .
	$row->manufacturer . "\t" .
	preg_replace($_strip_search, $strip_replace, strip_tags( str_replace(">", "> ", $row->name) ) ) . "\t" .
	preg_replace($_strip_search, $strip_replace, strip_tags( str_replace(">", "> ", $row->description) ) ) . "\t" .
	$row->product_url . "\t" .
	$image . "\t" .
	$row->id . "\t" .
	$row->products_quantity . "\t" .
	"\t" . //condition - not going to populate, optional field, populate at your own risk
	$row->products_weight . "\t" .
	"\t" . //ship cost - not going to populate, optional field, populate at your own risk
	"\t" . //bid - not going to populate, optional field, populate at your own risk
	"\t" . //Promo Des. - not going to populate, optional field, populate at your own risk
	"\t" . //Other - not going to populate, optional field, populate at your own risk
	$row->price . "\n";

$already_sent[$row->id] = 1;
}

If anyone can help me with this that would be great. Be gentle though I am still learning

-Thanks

    If you simply want to limit a given string to an arbitrary maximum length, then [man]substr/man would seem the simplest solution.

      9 days later

      Thanks for the reply, but how would I apply that to above?

      -Thanks

        If the desired max length was 50 characters, for example:

        substr(preg_replace($_strip_search, $strip_replace, strip_tags( str_replace(">", "> ", $row->description) ) ), 0, 50) . "\t" .
        

        However, without knowing what the preg_replace() is actually doing, I can't guarantee that the string won't be terminated at an inappropriate position.

          Thank you for your help. It worked perfectly. now I see how you did it I will have to remember this for next time. I didn't think it was that easy?

          -Thanks Again

            Write a Reply...