wemustdesign Posted March 16, 2009 Share Posted March 16, 2009 I am not sure if this is possible. I am wanting to automatically change text on my webpage into a link. For example the word orange may be declared as a keyword: oranges would be replaced by <a href='oranges.php'>oranges</a> Is it possible to do this automatically? If not is there any otherway this could be done? Quote Link to comment https://forums.phpfreaks.com/topic/149639-turn-keywords-into-links-automatically/ Share on other sites More sharing options...
Daniel0 Posted March 16, 2009 Share Posted March 16, 2009 str_replace('oranges', '<a href="oranges.php">oranges</a>', $text); Quote Link to comment https://forums.phpfreaks.com/topic/149639-turn-keywords-into-links-automatically/#findComment-785778 Share on other sites More sharing options...
Maq Posted March 16, 2009 Share Posted March 16, 2009 I'm sure you want this done dynamically, how are you retrieving these values? Quote Link to comment https://forums.phpfreaks.com/topic/149639-turn-keywords-into-links-automatically/#findComment-785782 Share on other sites More sharing options...
wemustdesign Posted March 16, 2009 Author Share Posted March 16, 2009 Thanks i will try this now Quote Link to comment https://forums.phpfreaks.com/topic/149639-turn-keywords-into-links-automatically/#findComment-785783 Share on other sites More sharing options...
wemustdesign Posted March 16, 2009 Author Share Posted March 16, 2009 The results are taken from a database and are outputted as variables Quote Link to comment https://forums.phpfreaks.com/topic/149639-turn-keywords-into-links-automatically/#findComment-785785 Share on other sites More sharing options...
wemustdesign Posted March 16, 2009 Author Share Posted March 16, 2009 Yes that worked fine. Is there any way to replace the word even if it has an uppercase? It worked fine for orange but does not change Orange Quote Link to comment https://forums.phpfreaks.com/topic/149639-turn-keywords-into-links-automatically/#findComment-785801 Share on other sites More sharing options...
Maq Posted March 16, 2009 Share Posted March 16, 2009 Use str_ireplace() Quote Link to comment https://forums.phpfreaks.com/topic/149639-turn-keywords-into-links-automatically/#findComment-785806 Share on other sites More sharing options...
Rodis Posted March 16, 2009 Share Posted March 16, 2009 str_ireplace — Case-insensitive version of str_replace(). Quote Link to comment https://forums.phpfreaks.com/topic/149639-turn-keywords-into-links-automatically/#findComment-785807 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.