Question

Here is my code.My destination was: i will enter some content text(like articles), keywords and site url. And in the end keyword in text will be linked to url i was given for once. But code doesnt work. So where is my mistakes?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
</head>

<body>

   <form name="form1" method="post" action="">
<div style="float:left">
<table width="40%" border="0" >   
<tr>
    <td height="30" class="yazi">Text</td>
    <td height="30">:</td>
    <td height="30">
    <span class="formyazi"><textarea name="text1" cols="75" rows="25"></textarea><br></span>
    </td>
</tr>

<tr>
    <td width="23%" height="30" class="yazi">Keywords</td>
    <td width="1%" height="30" class="style1">:</td>
    <td width="76%" height="30">
    <span class="formyazi"><input type="text" name="keywords" value=""></span>
     </td>
</tr>

<tr>
    <td width="23%" height="30" class="yazi">site adress</td>
    <td width="1%" height="30" class="style1">:</td>
    <td width="76%" height="30">
    <span class="formyazi">http://<input type="text" name="site" value="">/</span>
     </td>
</tr> 






<tr>
    <td height="55" colspan="3">
        <input type="submit" class="button" style="font-size:10pt;color:#FFFFFF;border-style:solid;border-width:1;background-color:#0D78B3" value="Send!">
    </td>
</tr>
</table>
</div>
 </form>  


<?php
$text2=$_POST["text1"];
$nesne=str_replace($keywords,'<a href="$link" title="$keywords" target="new">$keywords</a>',$text2 ,1);
$linkedtext=$nesne;
?>   
<div style="float:left">
<table width="40%" border="0" > 
<tr>
    <td height="30" class="yazi">Text with link</td>
    <td height="30">:</td>
    <td height="30">
    <span class="formyazi"><textarea name="cikti" cols="75" rows="25"><?php echo $linkedtext;?></textarea><br></span>
    </td>
</tr>
</table>
</div>
</body>
</html>
Was it helpful?

Solution

Since you've gotten the correct $_POST variables according to your comment, you need to fix this now

$nesne=str_replace($keywords,'<a href="$link" title="$keywords" target="new">$keywords</a>',$text2 ,1);

You cannot put variables in a single-quote delimited string - use double quotes around it with single-quotes inside.

Like this:

$nesne=str_replace($keywords,"<a href='$link' title='$keywords' target='new'>$keywords</a>",$text2 ,1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top