Question about str_replace


Hello there,

im trying to develop a webshop with some code i picked up somewhere, cosmicshoppingchart (very easy to set up).

Now in the scripts all is parsed into templates by php so the catalog is completely dynamic build.

Now comes my problem: in 1 of the included files the parsing of the category names is done:

if (strpos($template, “::category_links::”)) {
$cats = db_get_cats_result();
while ($cat = mysql_fetch_assoc($cats)) {
$cat_lnk = $templates[“category_link”];
$cat_lnk = str_replace("::category_id::", $cat[“cat_id”], $cat_lnk);
$cat_lnk = str_replace("::category_name::", $cat[“cat_name”], $cat_lnk);
$rtn_cats_lnk .= $cat_lnk;
$template = str_replace("::category_links::", $rtn_cats_lnk,$template);

What this does is replace the ::category_link:: with all the categorys printed after another.

I want the categories displayed beneath eachother so i have to break the category_links into 1,2,3 etc.

Omeone gave me a tip of trying to add in the
somewhere but i didn’t get that to work.

Can somebody help my out please?


Yes, the tip you recieved was correct, you should add in a </ BR> tag. Now, comes the question of where. As I was looking through the code, I started to wonder where did $rtn_cats_ink come from cause that is where the list seems to becoming from. So here is where I would try and add the </ BR> tag…

instead of having:

$rtn_cats_lnk .= $cat_lnk; 

replace with

$rtn_cats_lnk . = $cat_lnk . "</ BR>";

That should make them line break.


I tried your solution but still not working.

Although breaks are appearing in the source now:

but it seems they are in the wrong place, now the table is the height it should be but the categories still are horizontal and sit on the bottom now.

Strange :o

  Chardonay   Cabernet Sauvignon   Pinot Gris  


I didn’t know the results were being outputed to a table, you will need to
take and make

tags in there. That way each one will have its
own row.


But enough for today, i’ll look into it again tomorrow.