Basically what I am trying to do is to create custom tags that can be used on my site to create links to other player profiles (it's a game site). I got this far: if(strpos($var,'[pl]') && strpos($var,'[epl]')){; $var = str_replace("[pl]$var[epl]", "<a href=\"player.php?\mob=$var\">$var</a>", $var); } PHP: Basically it looks if the $var (input) contains the starting tag [pl] and ending tag [epl] (it didn't let me use [/pl] in str_replace, so I'm using [epl] instead. But I just realized that it's totally wrong... The key question here is how to assign the text between the tags to a new variable (from the input, so I can make the link work properly)? Right now it treats the whole text ($var) as a link and isn't functioning as it should..
You should consider using a regular expression for this. use $var = preg_replace('/[pl](.*?)[\/pl]/', '<a href="player.php?mob=$1">$1</a>', $var); PHP: That will match between the [pl] and [/pl] for you, capture whatever it is and put it in the a's href and content
You most likely need to need to use preg_replace. Can you give an example of what the variable $var is before you start the strpos functions? I'm not clear on what you;re trying to accomplish by the str_replace.
I don't think it's working properly... Here is what happened: $var = "This is a test message [pl]Bull[/pl] - that is a player name that should turn into a hyperlink."; PHP: Here is what is usually done with the $var $var = str_replace("\n","<br>", $var); $var = str_replace("[b]","<b>", $var); $var = str_replace("[/b]","</b>", $var); $var = str_replace("[i]","<i>", $var);$var = str_replace("[/i]","</i>", $var); $var = str_replace("[u]","<u>", $var);$var = str_replace("[/u]","</u>", $var); PHP: Now, I've added your line to the end: $var = preg_replace('/[pl](.*?)[\/pl]/', '<a href="player.php?mob=$1">$1</a>', $var); PHP: The result: This is a test message [<a href="player.php?mob="></a>]Bu<a href="player.php?mob="></a>[/<a href="player.php?mob="></a>] - that is a <a href="player.php?mob="></a>ayer name that shou<a href="player.php?mob=d%20turn%20into%20a%20hy">d turn into a hy</a>erlink. PHP: I think I answered your question up there. $var is basically raw user input that is formatted for the database. There was some kind of a trick to extract the text between the tags, but I can't remember it. Regex is a nice way to do it too though, but I suck at that to be honest.