Hi There,
Im an absolute beginner when it comes to programming.
I am trying to write a function, but I wouldn't know where to start.
Essentially I have a database with a table named: products_order_links
within that table is a field called: paydotcomlink
What happens is that users submit a link, in which we have strip it down to its essential and reuse it for another function.
In all cases, people will enter code like this into the paydotcomlink field
<a href="https://paydotcom.com/sell.php?id=10533" target="_blank"><img border="0" src="https://www.paypal.com/en_US/i/btn/x-cl ... c.gif"></a>
What i wanna do is just strip down that code so that i only get the id "10533" and save it as a variable so i can reuse it elsewhere. Obviously, the ID changes everytime, so it is not always 10533 - which is why I need to save it as a variable.
Any suggestions?
Variables
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
What you are asking is similar to a form where you have on of two methods, GET and POST.
method="get": This method sends the form contents in the URL: URL?name=value&name=value. Note: If the form values contains non-ASCII characters or exceeds a certain number (cannot remember exactly how many) characters you MUST use method="post" or encode the text as a url.
method="post": This method sends the form contents in the body of the request. Be aware you cannot bookmark post requests.
As you should be able to see the 'https://paydotcom.com/sell.php?id=10533' is part of the url and should be processed as though it is a form. The name/value pairs of the GET method are stored automatically in an array called $_GET. To use you could use the following:
Obviously you may also want to check if the value is also an integer in the expected range. Always follow the rule NEVER trust user input.
method="get": This method sends the form contents in the URL: URL?name=value&name=value. Note: If the form values contains non-ASCII characters or exceeds a certain number (cannot remember exactly how many) characters you MUST use method="post" or encode the text as a url.
method="post": This method sends the form contents in the body of the request. Be aware you cannot bookmark post requests.
As you should be able to see the 'https://paydotcom.com/sell.php?id=10533' is part of the url and should be processed as though it is a form. The name/value pairs of the GET method are stored automatically in an array called $_GET. To use you could use the following:
Code: Select all
<?php
$myvar=0;
if (!empty($_GET['id'])) {
$myvar=$_GET['id'];
}
...
?>