Jump to content

[SOLVED] Replace


Minase

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/119805-solved-replace/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617206
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617211
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617215
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617221
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617227
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/119805-solved-replace/#findComment-617236
Share on other sites

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.