Jump to content

Recommended Posts

Well, using the little php I know I have come up with this:

 

<?php
		function changelink($change)
            {
		$find = "htmlspecialchars($row["source"])";
  $replace = "<a href="http://www.amazon.co.uk/dp/($row["source"])?tag=speciainvita-21&camp=1406&creative=6394&linkCode=as1&creativeASIN=($row["source"])" />";
  
  


  $change = preg_replace($find, $replace, $change);
  return $change;
}


             <?php echo $change; ?>

 

Which obviously doesn't work!

 

What I am trying to do is insert "source" into various places in the bottom line. I am guessing there is another way of doing this apart from the find and replace method as I am guessing trying to find a string will not work. I just wanna know how to do this! I welcome anyone who can show me how to do this and explain how it works as I am really trying to learn php and not just copy and paste!

 

This is the line originally:

 

<?php echo htmlspecialchars($row["source"]); ?>

 

and "source" is gathered using:

 

<input name="source" type="text" value="<?php echo htmlspecialchars(stripslashes($source)); ?>" maxlength="255" size="50"/>

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/88116-solved-correct-my-code/
Share on other sites

that will never work ever regardless of if you fix quotes

 

 

go to php.net and look at variable scope you are trying to use global variables (or what looks to be global) in a function and that isn't going to work with your syntax.

 

$row['source'] is undefined in the function thus it can't do anything about it.

 

 

Your even trying to use the local variable $change outside the function in the global area that won't work also.

that will never work ever regardless of if you fix quotes

 

 

go to php.net and look at variable scope you are trying to use global variables (or what looks to be global) in a function and that isn't going to work with your syntax.

 

$row['source'] is undefined in the function thus it can't do anything about it.

 

 

Your even trying to use the local variable $change outside the function in the global area that won't work also.

oh sorry i don't see that i though its not inside the function and i dont see this function changelink($change)

Ok,

 

The user inserts a product number, for example : 1000 and it is stored using this:

 

<input name="source" type="text" value="<?php echo htmlspecialchars(stripslashes($source)); ?>" maxlength="255" size="50"/>

 

I then want to display "source" inside a line:

 

i.e

 

http://www.amazon.co.uk/dp/"source"?tag=speciainvita-21&camp=1406&creative=6394&linkCode=as1&creativeASIN="source") using the echo

 

Is this possible?

 

Thanks dude

 

sorry post updates : I know I am using the wrong syntax, i just have no idea what to use or what it does, it is outside my limited knowledge of php :)

 

try

 

 

<?php
		function changelink($change)
            {
		$find = "source";
		$replace = htmlspecialchars($change);
  $change = '<a href="http://www.amazon.co.uk/dp/(source)?tag=speciainvita-21&camp=1406&creative=6394&linkCode=as1&creativeASIN=(source)" > test</a>';
  

$change2 = str_replace($find, $replace, $change);
  
echo $change2;
}
changelink($row["source"]);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.