Minase Posted August 15, 2008 Share Posted August 15, 2008 hy there i do have a whole string lets say $test = "Welcome to my topic !:TWelcome!" i want to take the variable $test and replace from it just !:TWelcome!. !:T - is to check if it is for replace , Welcome (should be replaced with a custom value) and ! put the end of value how can i do such a thing,if they are more than 1 syntax? like : !:TWelcome! => <a href="welcome">Welcome</a> Welcome is dynamic there can be anything else. thanks Quote Link to comment https://forums.phpfreaks.com/topic/119805-solved-replace/ Share on other sites More sharing options...
ratcateme Posted August 15, 2008 Share Posted August 15, 2008 $name = substr($text,strpos($text,"!:T")+3); echo "<a href=\"$name\">$name</a>"; Scott. Quote Link to comment https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617203 Share on other sites More sharing options...
Minase Posted August 15, 2008 Author Share Posted August 15, 2008 thanks but the thing is that i want to stop at the last ! sign after Welcome $text = "welcome to my first atempt of replace !:TMinase! dasdsa dasd"; $name = substr($text,strpos($text,"!:T")+3); echo "<a href=\"$name\">$name</a>"; it return what is after Minase with ! too (that ! should disapear and continue with normal text after it) thanks btw how can i do in php procent? like: $test = 10 + 10%; i did try a lot of methods nothing worked thanks Quote Link to comment https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617206 Share on other sites More sharing options...
ratcateme Posted August 15, 2008 Share Posted August 15, 2008 $pos = strpos($text,"!:T")+3; $len = strpos($text,"!",$pos) - $pos; $name = substr($text,$pos); $num = 10; $test = $num + $num*1/10; Scott. Quote Link to comment https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617210 Share on other sites More sharing options...
Minase Posted August 15, 2008 Author Share Posted August 15, 2008 thanks for procent thing,but the replace doesnt work,it is like before $text = "welcome to my first atempt of replace !:TMinase! dasdsa dasd"; $pos = strpos($text,"!:T")+3; $len = strpos($text,"!",$pos) - $pos; $name = substr($text,$pos); echo "<a href=\"$name\">$name</a>"; the ! after name should disapear (and only that,not in whole text) thank you again Quote Link to comment https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617211 Share on other sites More sharing options...
ratcateme Posted August 15, 2008 Share Posted August 15, 2008 sorry silly error on my part i forgot to add in the $len i just calculated it try this $name = substr($text,$pos,$len); Quote Link to comment https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617214 Share on other sites More sharing options...
Minase Posted August 15, 2008 Author Share Posted August 15, 2008 that seems to work,but the rest of text is gone ??? thanks //edit example of output $text = "welcome to my first atempt of replace !:TMinase! dasdsa !dasd"; - original $text = "welcome to my first atempt of replace <a href = \"Minase\">Minase</a> dasdsa !dasd"; i need the user (minase into a variable,cause it will be a query after it,and after that the original echo) thank you Quote Link to comment https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617215 Share on other sites More sharing options...
ratcateme Posted August 15, 2008 Share Posted August 15, 2008 i am a little lost but i think this is what you want $text = "welcome to my first atempt of replace !:TMinase! dasdsa dasd"; $pos = strpos($text,"!:T")+3; $len = strpos($text,"!",$pos) - $pos; $name = substr($text,$pos); $a = "<a href=\"$name\">$name</a>"; echo str_replace("!:T{$name}!",$a,$text); Scott. Quote Link to comment https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617221 Share on other sites More sharing options...
Minase Posted August 15, 2008 Author Share Posted August 15, 2008 sorry for soo much replys,but that doesnt seem to work,dont worry i tryed to change the code a bit,but still doesnt work... this is what your code return welcome to my first atempt of replace !:TMinase! dasdsa dasd it should be welcome to my first atempt of replace <a href="Minase">Minase</a> dasdsa dasd thank you again for your time Quote Link to comment https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617227 Share on other sites More sharing options...
ratcateme Posted August 15, 2008 Share Posted August 15, 2008 sorry left out the $len again try this $text = "welcome to my first atempt of replace !:TMinase! dasdsa dasd"; $pos = strpos($text,"!:T")+3; $len = strpos($text,"!",$pos) - $pos; $name = substr($text,$pos,$len); $a = "<a href=\"$name\">$name</a>"; echo str_replace("!:T{$name}!",$a,$text); Scott. Quote Link to comment https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617236 Share on other sites More sharing options...
Minase Posted August 15, 2008 Author Share Posted August 15, 2008 ya saw now thank you very much this works great. again thank you Quote Link to comment https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617237 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.