Jerred121 Posted July 20, 2010 Share Posted July 20, 2010 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... Link to comment https://forums.phpfreaks.com/topic/208354-find-and-replace-strings-based-on-symbol-can-you-change-header-from-body/ Share on other sites More sharing options...
bspace Posted July 21, 2010 Share Posted July 21, 2010 as regards question 1 changing your string into an array may be the way to go explode("::", $string) Link to comment https://forums.phpfreaks.com/topic/208354-find-and-replace-strings-based-on-symbol-can-you-change-header-from-body/#findComment-1088881 Share on other sites More sharing options...
Jerred121 Posted July 21, 2010 Author Share Posted July 21, 2010 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 Link to comment https://forums.phpfreaks.com/topic/208354-find-and-replace-strings-based-on-symbol-can-you-change-header-from-body/#findComment-1088935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.