Jump to content

find and replace strings based on symbol & can you change header from body?


Jerred121

Recommended Posts

Hey guys, 1st time poster and I'll try not to be a troll but I've got a a couple of questions:

 

1st question)

I was wondering what the best way to replace certain strings is:  I have a lists of ingredients stored on my database in a varchar that are separated by two :'s like ":ingredient1::ingredient2:" and what I want to do is echo the ingredients as links like, <a>ingredient1</a>, <a>ingredient2</a>, etc...

 

I figured I would have to return the position of the first colon (:) then the second colon and use those positions to extract and replace it all with the <a>Ingredient 1, </a>.  I was just curious as to what the easiest/most effective way to accomplish this would be.

 

2nd question)

I was curious if it was possible (with php or other language) to change the <title> element from with in the body of a page.  I mean I guess it'll work with javascript but for some reason I had ruled that out, but now that I'm rethinking it that might be the way I go.  The reason why I want to do this is because I'm going to use includes for my header and a lot of the content I'll be repeating (header, banner, nav bar, side bar, etc.) so i would like to be able to change the <title> from within the body.  I figure a few solutions here, but I was just looking for more options to weight.  Thanks for any help...

Nice! thanks bspace that was a lot better than what i had in mind.  here is what I did:

$ingredientsArray = explode("::",$prodArray['ingredients']);
$ingAmt = count($ingredientsArray);
$ingRow = 0;
while ($ingAmt > 2){
$ingAmt --;
echo "<a href='#'>".$ingredientsArray[$ingRow]."</a>, ";
$ingRow ++;
}
//so the last one doesn't have a comma
if ($ingAmt = 2){
echo "<a href='#'>".$ingredientsArray[$ingRow]."</a>";
}

thanks man

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.