fizix Posted December 22, 2006 Share Posted December 22, 2006 OK, all I want to do is match the string "%1" in regex. I've tried a million different ways but it's not working. Can anybody tell me how?Thanks! Link to comment https://forums.phpfreaks.com/topic/31618-solved-pulling-my-hair-out/ Share on other sites More sharing options...
obsidian Posted December 22, 2006 Share Posted December 22, 2006 Try this:[code]<?php$String = "My string contains %1";if (preg_match('|\%1|', $String)) { // String contains your match}?>[/code] Link to comment https://forums.phpfreaks.com/topic/31618-solved-pulling-my-hair-out/#findComment-146537 Share on other sites More sharing options...
utexas_pjm Posted December 22, 2006 Share Posted December 22, 2006 If you're trying to match a string that is static, like "%1" it is more efficient to use a string matching function than regex (I'll save you the explanation unless you're curious) so the following code would (theoretically) accomplish the task in less time.[code]<?phpif (strpos($String, '%1') !== false){ // Match}?>[/code] Link to comment https://forums.phpfreaks.com/topic/31618-solved-pulling-my-hair-out/#findComment-146541 Share on other sites More sharing options...
fizix Posted December 22, 2006 Author Share Posted December 22, 2006 Thanks! Link to comment https://forums.phpfreaks.com/topic/31618-solved-pulling-my-hair-out/#findComment-146546 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.