Hallo zusammen, ich versuche in Anlehnung an den folgenden kleinen Code Snippet, welcher funktioniert, Parameter aus einer Url auszulesen.
Das sieht dann bei mir in etwa so aus:
Leider tut das untere, von mir angepasste Snippet überhaupt nichts. Hat jemand eine Idee, warum ich hier auf dem Holzweg bin? Für mich ist das Verfahren die Parameter über named subpatterns auszulesen wichtig. Eine Lösung mit explode und substring würde mit wachsender Anzahl an Parametern zu kompliziert.
Vielen Dank für eure Anregungen
PHP-Code:
<?php
//////////
// Das funktioniert!
//////////
//First we set the url variable here
$url = 'website_url/website_name/generatebuynowbtn.php?id=65&num=1';
//We search for a match to grab the id value and the num
//value in the url variable above
preg_match('#\?id=([0-9]+)\&num=([0-9]+)#',$url,$variables);
//We assign the values to their own variables and
//make sure they are a number with int()
$url_id = intval($variables[1]);
$url_num = intval($variables[2]);
print "url_id: " . $url_id;
print "url_num: " . $url_num;
?>
Das sieht dann bei mir in etwa so aus:
PHP-Code:
<?php
//////////
// Das hier nicht!
//////////
$url2 = 'http://www.site.de/test.php?k=o2p2s3u6g7l2t3v3r344u3o2g4x3p2o3s626s3m2l2v3o2y3j2a3o2q2o33836l2d2v3l2p2v3j243&p=o2p2s3u6g7l2t3v3r344u3o2g4x3p2o3s626s3m2l2v3o2y3j2a3o2q2o33836l2d2v3l2p2v3j243';
//We search for a match to grab the p value and the k
//value in the url variable above
preg_match('#\?k=([0-9a-b]*)\&p=([0-9a-b]*)#',$url2,$variables2);
print_r($variables2);
$k = $variables2[1];
$p = $variables2[2];
print "k: " . $k;
print "p: " . $p;
?>
Vielen Dank für eure Anregungen

Kommentar