kid85 Posted December 27, 2007 Share Posted December 27, 2007 I use this link to add products to my cart: <a href="../folder/file.php?action=addginseng01<?php // ,product name - per box,25.95?> 1. How can I write something which returns the word that is between "add" and "01" which is "ginseng".) 2. Secondly, I need to extract the middle black part of this string as well. I tried using preg_match but I can't get it to work. addginseng01<?php // ,product name - per box,25.95?> preg_match('/('.$_GET["action"].'<\?php[ \t]\/\/[ \t])(\?>)/i', $filecontents, $target) Can anybody help ? Quote Link to comment https://forums.phpfreaks.com/topic/83373-solved-preg_match-regex/ Share on other sites More sharing options...
MadTechie Posted December 27, 2007 Share Posted December 27, 2007 Erm.. What the ..... I started to tidy it up but the code doesn't make much sense.. Quote Link to comment https://forums.phpfreaks.com/topic/83373-solved-preg_match-regex/#findComment-424217 Share on other sites More sharing options...
kid85 Posted December 27, 2007 Author Share Posted December 27, 2007 Basically, how can I write something which returns the word that is between "add" and "01" which is "ginseng". Anybody can help me? Quote Link to comment https://forums.phpfreaks.com/topic/83373-solved-preg_match-regex/#findComment-424231 Share on other sites More sharing options...
MadTechie Posted December 27, 2007 Share Posted December 27, 2007 like this <?php //if $_GET["action"] = addginseng01 then $result will = ginseng $result = ""; if (preg_match('/add([^\d]*)/i', $_GET["action"], $result)) { $result = $result[1]; // = ginseng } echo $result; ?> EDIT: You could also use, IF the word may contain numbers if (preg_match('/add(.*?)\d{2,2}/i', $_GET["action"], $result)) Quote Link to comment https://forums.phpfreaks.com/topic/83373-solved-preg_match-regex/#findComment-424271 Share on other sites More sharing options...
kid85 Posted December 27, 2007 Author Share Posted December 27, 2007 Your code was perfect. I can't figure the last part : This is the code to search for and return the middle black part addginseng01<?php // ,product name - per box,25.95?> I tried this but seems light years away. $target = ""; if (preg_match('/('.$_GET["action"].'<\?php[ \t]\/\/[ \t])(\?>)/i', $filecontents, $target)) { $target = $target[1]; } print $target; Quote Link to comment https://forums.phpfreaks.com/topic/83373-solved-preg_match-regex/#findComment-424309 Share on other sites More sharing options...
MadTechie Posted December 28, 2007 Share Posted December 28, 2007 Okay, i'm kinda confused can you post an example of the text you have and the text you want it to be ie i have the quick brown fox jumped over the lazy red dog and want it to be the quick brown fox Sat On the lazy red dog Quote Link to comment https://forums.phpfreaks.com/topic/83373-solved-preg_match-regex/#findComment-424396 Share on other sites More sharing options...
kid85 Posted December 28, 2007 Author Share Posted December 28, 2007 I figuered it out, thank you very much for your expert help. Quote Link to comment https://forums.phpfreaks.com/topic/83373-solved-preg_match-regex/#findComment-424578 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.