Regex Doesent Work Expected...
i use this to get all html tags out of an string ..
preg_match_all('/<[^>]*>|[^<>]+/', $data, $contentParts);
worked wonderful till i noticed that this doesent work with something like
"{if $commandCount > 0}"
this will be split in 2 parts:
"{if $commandCount " and " 0}"
and the < is gone
It shouldnt split anyway when it detects an " < " or ">=" or " <=" and so on..
View Complete Forum Thread with Replies
Sponsored Links:
Related Messages:
Buffer Flush Doesn't Work Quite As Expected
I've got a PHP script (running on MacOS X, PHP 4.1.12) which uploads bookings from one database to another, and I'd like to have the screen show progress as it happens (each time I process a booking, I write a line summarising it to the browser with 'print') From RTFMing and Googling, it seems that I should be able to do this by turning output buffering on and using ob_flush() et al. However, this only sort-of works, in that instead of getting output line by line, I get a multi-line chunk on the browser from time to time. Am I stuck with having this chunk-by-chunk visualisation, or can anyone please suggest a way that I can make it force each line to the browser as I write it?
View Replies !
View Related
Line Breaks Don't Work As Expected
I wrote this small bit of code for a college class, but the instructor offered no feedback. Our textbook offered nothing and the teach yourself book I bought had typos in it. :mad: I don't understand why the linebreaks in the php code didn't work properly. I ended up putting them at the beginnings of the next line, rather than the end of the previous line. I think that's sloppy; I want to undertand why the line break worked on the first line but not subsequent lines. I expect it's something semantic, quotes or such. Code:
View Replies !
View Related
Need MD5 Support But The Provider Doesent Have It Installed
Like the subject says I need the md5 functionality of php but unfortunatly my hosting provider doesent have it installed. So instead of paying a grand to get it installed we are going to wait the 2 months needed for their next upgrade cycle. There is a problem with this though. I have a client that just decided to handle cc payments through authorize.net and they need an md5 has as part of their form post. I had a couple of ideas and I would like to know if anyone things they are possible and if not if there is another or even better way to handle this. 1 since php can send shell commands im thinking of writing a small exe in c++ that will take the parameters needed and return the md5 hash. Im not sure about this because I dont know how php handles output from stdout 2. I believe our hosting provider has the perl md5 module installed so I can try using some perl inside of the php code. However Im not quite sure if you can do this or even how to considering ive never used perl. 3. Write some sort of cgi app which i believe might be similar to my first option to handle the md5 hash. Any suggestions or 3rd party md5 libs that I can plug directly into my page would be greatly appreciated.
View Replies !
View Related
Expected Output
When I try to test my setup by making the file test.php with the single line PHP Code: <?php phpinfo(); ?> then goto http://localhost/test.php it displays Quote: <?php phpinfo(); ?> instead of all the info.
View Replies !
View Related
T_OLD_FUNCTION Expected???
I use EngIn editor, my code ran ok there... but not when I ran it on my apache server.. got the following error: Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in C:japachecaseFileCVf.php on line 5 Here's the code:
View Replies !
View Related
Loop Expected
i get it to loop, so that it keeps doing it for; $start =10 then 20 etc right up to 1000 the function is; function query($topic, $start = 0) { $googlelist = $this->_query("Google", $topic, $start); $yahoolist = $this->_query("Yahoo", $topic, $start); $this->found = array_unique(array_merge($googlelist, $yahoolist)); $this->counts = array("yahoo" => count($yahoolist), "google"=> count($googlelist), "total" => count($this->found)); return true;.
View Replies !
View Related
Could The Close_date Be One That Is Not The Expected Value?
Here's the code. $link="http://xbox360cheat.org"; $close_date=$_POST["close_date"]; #last content change check if ($close_date == 0) $close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date ("d")+7, date("Y"))); else if ($close_date == 1) $close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date Could the close_date be one that is not the expected value? For example, if the month is 11 and $close_date == 7, then the mktime function should return the next year for the year value, not the current year. And if the day is the last week of December, than the month and year should change if close_date == 7.
View Replies !
View Related
Implode() Not Working As Expected
I have one page with a form that uses an array ($order) to print out ordered items. This page then posts to a second page to get personal information from the person ordering. Before posting the form, I implode the array into another variable ($items_ordered), so that I can print a summary of the items ordered on the second page. (The following code is all within the <form> tags.): Code:
View Replies !
View Related
NULL Expected, Won't Show Up ...
I have tho following code. $_GET['artile'] looks like this: /2006/03/lorem_ipsum $locationinfo = explode('/', trim( $_GET['article'] , '/') ); list( $article_year, $article_month, $article_url ) = $locationinfo; echo '<br>year: '.(($article_year === NULL)? 'null': $article_year); echo '<br>month: '.(($article_month === NULL)? 'null': $article_month); echo '<br>article: '.(($article_url === NULL)? 'null': $article_url); The weird thing is, if $_GET['article'] is empty, $article_year isn't NULL, but the rest is. This doesn't make any sense to me ...
View Replies !
View Related
Ini_set() Not Working As Expected
When running the following code I get a warning: <? ini_set('session.use_cookies',0); ?> random text <? session_start(); ?> The output / warning I'm getting is this: random text Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /path/to/file.php:5) in /path/to/file.php on line 6 Shouldn't the fact that I'm setting session.use_cookies to 0, via ini_set, prevent this error from taking place?
View Replies !
View Related
Preg_replace Not Matching As Expected
I'm attempting to write a bit of code that will parse a HTTP_REFERER from google and return the search data and the nationality (.fr, .co.uk, etc). I can get a rough output (see bellow) but the search value (2 in the script) continues past the '&' character which is where I need it to stop. PHP Code:
View Replies !
View Related
Function Not Returning Expected Value
I have a php file that contains a couple of arrays used for state/country pull-down lists. I have two global arrays and an accessor method for each. I have some simple logging methods, so I know a little bit about what I'm getting back. When I try to get the arrays from another file using the accessor methods, I get no array back. Within the file that contains the arrays, I can access them by global name and also by the accessor methods. Any ideas why I cannot access the arrays from another file? Code below. <SNIP FROM CALLING METHOD> require_once BASE . '/config/formfields.inc.php' // file with needed arrays // the calling method function display_states($smarty){ logobj(function_exists(get_states)); // returning True/1 $s = get_states(); logobj($s); // no love here logobj(BASE . '/config/formfields.inc.php'); // it's the right file }
View Replies !
View Related
CURL Results Not What Expected
I was playing with cURL on a website and it didnt work. So I switched to a different website and it worked just fine. So that little part of my brain that is always working started wondering why cURL wouldnt work with the first website that I had tried. I'm hoping that someone here can help me figure out why this particular website wont work with my cURL script, and help me get it working. Code:
View Replies !
View Related
Sort Results Not As Expected
In the actual array I'm working with, the a, b, c's are primary keys. One shouldn't expect them to actually be in order. This example uses a, b, c to verify if a sort worked properly. I want to sort the array so the result will have a,b,c,d,e,f,g,h, etc in order. Code:
View Replies !
View Related
Not Getting Expected MySQL Error
I am inserting values into a row.. works OK If I try to insert a value into a row that doesnt exist (using where) it always returns true the same as if it did work I want to update rows that have one unique field.. if the row doesnt exists it should return 0 rows updated.. I then create the row... But it always returns 1 even when I update a row that doesnt exist.. How do I get an error or a false return?
View Replies !
View Related
Ereg Not Behaving As Expected
I'm having a problem with the ereg function to verify a user submitted variable the situation is that the user is submitting a textarea post variable there are a number of allowed characters there are more in the actual application but i have removed to demonstrate the problem as removing them makes no difference the php code is as follows: $message=$_POST['textarea1']; if (ereg("^[A-Za-z0-9 ]*$",$message)) { $textValid=TRUE; } else { echo "error"; } but it seems to act like $message=$_POST['textarea1']; if (ereg("^[A-Za-z0-9]*$",$message)) { $textValid=TRUE; } else { echo "error"; }
View Replies !
View Related
Unexpected Absence Of Expected Warning
The page 167 of book Learning PHP5 by David Sklar says that setcookie() and session_start() must be added before any output. I tried to use that functions at last line but no warning!. The warning which i got 1 month back is not issued now. ------------------------------------------------------------------ The following is my PHP program <?php function Intelli() { echo"Hello P"; } function Bitz() { echo"Hello MySQL"; } ; $a = 1; if($a) $myFunc = 'Intelli' else $myFunc ='Bitz' $myFunc(); print'header' session_start(); setcookie('userid') ?> ---------------------------------------------------------------- The following is the output i got. There is no warning [tdphpadmin@trgbws40 ~/public_html/demo]$ php dynamicfun.php X-Powered-By: PHP/5.2.0 Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/ Set-Cookie: PHPSESSID=bp1m17rlrgsa5g19tfekidov31; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre- check=0 Pragma: no-cache Set-Cookie: userid= Content-type: text/html
View Replies !
View Related
Predefined Variable Not Working As Expected
I have a script that was working fine until I had to reinstall everything. Now my scripts says that : PHP Notice: Undefined index: LOGON_USER in D:Inetpubwwwroot ame.php on line 5 Where I have just made a new file to isolate the issue, but this derives from this script : <?php echo $_SERVER['LOGON_USER']; ?> Which worked fine before. Is this down to the way php is being run? As it stands it is being run via IIS 5 as cgi executable. I've looked over the install txt and it seems as though I have done everything correct.
View Replies !
View Related
Delete Query Not Working As Expected
I have 2 different php forms. One makes sure that a user has chosen an unique user name (below): $query_rsApp = "SELECT * FROM users where UserName=".$Registered." "; This Select query works right every time (as far as I can tell). I have a form that I want to use to delete user records. This Delete query works fine if the username and password are both numeric... But if the username or password is text, it returns the error "UNKNOWN FIELD 'whatever'" where whatever is my search criteria that I am trying to use.
View Replies !
View Related
Imagecolortransparent Not Working As Expected - Any Ideas?
I'm trying to rescale a gif file with transparency but am having difficulty with the imagecolortransparent() function - It's not working as I would hope... I'm telling it to replace the colour red with transparency and then overlay my transparent gif, but resized. For some reason, it is turning anything black in my transparent gif, transparent, instead of the red - Can anyone else figure out why it might be doing this? Code:
View Replies !
View Related
Elegantly Handling An Expected Error
I have a very modest database on my server and I use php to allow people to query it. Its very simple, they enter a value that should be in column 1 (account_num) and I return the value for column 2 (balance) (same row). Here is the question: What if the value they enter doesn't match any values in column 1? Right now, I get this ugly error message: Code:
View Replies !
View Related
Problem Getting Script's URL ($_SERVER['PHP_SELF'] Not What I Expected)
I have a function that restricts access to a page to logged in users. When a user who isn't logged in goes to the page, it will dynamically generate a login form. I'm trying to use it in conjunction with the free shared SSL certificate offered by my host. To use SSL, you would change a URL like this http://mydomain.com/page.php to https://ssl.myhost.com/mydomain.com/page.php My problem: when my script dynamically generates the login form, it uses the $_SERVER['PHP_SELF'] value in the action field. But this ends up being '/page.php' rather than '/mydomain.com/page.php' so my form gets submitted to https://ssl.myhost.com/page.php instead of https://ssl.myhost.com/mydomain.com/page.php Simple I thought, I'll just use the SERVER or ENV variable that gives me the full url. My problem: it doesn't seem to exist!
View Replies !
View Related
PHP Seems To Work Half The Time, Phpinfo() Doesn't Work
I just updated from a phptriad installation of apache/php/mysql to manual installations of them, all the most current ones. When I installed apache and php, things were fine. phpinfo loaded. After I installed mysql, things started messing up. I can connect to mysql so that seemed to go fine. But phpinfo wouldn't list MySQL info. So, I noticed I had the path to PHP in my httpd.conf wrong, I fixed it, restarted and thats when it all started. I added the "php extension" line , enabled php_mysql.dll module, as well as putting libmysql.dll into my windows folder. Restarted the computer, and still problems. What happens exactly is, if I go to my phpinfo.php page which has a simple phpinfo(); line...it doesn't show anything. If I View Source, I actually see the php code in notepad. <? phpinfo(); ?>On other pages it prints some of the php code on screen. But on a few other pages, such as a page that creates and image via imagecreate()...it works.
View Replies !
View Related
Regex How To?
$string = "this is a test string"; $part_of_string = "ring"; $new_string = ereg_replace ($part_of_string , "reet", $string); echo $new_string; This works, it replaces ring with reet, but this is not what i want I want to replace a whole word, not any part of a word example: $string = "the word i want to replace is his not this" But eregi_replace would replace this and his, but i only want to replace the whole word "his" Does anyone now how to look for and replace a whole word and not replace part of a word.
View Replies !
View Related
A Little RegEx Help Please
I'm trying to match a pattern with a regular expression, but I have very little experience using them. The pattern I'm trying to match is a string where the first two characters are numbers between 0 and 9 and then anything else can follow. Then I want to make the string just equal to the first two digits of the string. So the string "430asdf34845sjka" is passed to the function, I want it to return the string "43". If the string "4q34423234" is passed, I want it to reject the string. From looking at a few tutorials on the net I have devised the following incorrect pattern matcher : ^[0-9]*[0-9]*.* Immediately I know the *'s after the [0-9] are wrong, but I'm not sure what to replace them with, * meaning match 0 or more of the preceeding character? Would: ^[0-9][0-9].* be more like it? Plus how do I just take the first two characters and make them the new value of the variable.
View Replies !
View Related
Regex
I have created my own regex (which is why its not working) :-( which should allow a minimum of one word and a maximum of 3 words with each word being separated by a space character or a hyphen character. Each word will be at least one alpahanumeric character in length. However when given the $subject == 'one two three', my program outputs 'pattern did not match' which is not correct. PHP Code:
View Replies !
View Related
A Little Regex Help?
How do I write a regex that matches http://att.com and http://www.att.com but doesn't match http://matt.com or http://www.bratt.com? I'm trying to create a whitelist but I keep ending up with sites I don't want matching my criteria. I just can't seem to get my head around it.
View Replies !
View Related
Need Help With RegEX
I want to change a given string in a way that: 1) all invisible chars (like ALT+0254) will be changed to spaces 2) all sequence of several whitespaces will be changed to a single space. 3) leading and trailing spaces will be canceled (I know how to do that with trim, so this is only nice-to-have) I cant limit the string to a-zA-Z0-9 because that every visible char is OK (it's a multi lingual site).
View Replies !
View Related
Need Help For Regex
I need a regex (may be together with a php function) to retrieve information within '[' and ']' in a line of text. Here is an example: hello world, example [demo|123] line with some [$55] yesys [no]. I need to retrieve all the three pieces of text enclosed in [] pairs.
View Replies !
View Related
Regex XOR?
Is it possible to make a regular expression that matches in a XOR/exclusive disjunction way? For example, something like this: "some text / some more text" does not match "some text /" does match "/ some more text" does match "/" does not match I think this should be easy, but I can't seem to find a way to do it.
View Replies !
View Related
PHP Regex Help
PHP regex. What I am trying to match is: it's a mysql/php field. Then if a match I take some action. But it's not working any help appreciated. Thanks while ( $row = mysql_fetch_row( $result ) ) {... ..... foreach($row as $data) { if ( preg_match ( "/http://library.dayton.town.net/", $data ) ) $data= 'You got a match'
View Replies !
View Related
More Regex
I was reading through someone else s code earlier and I came across this regex $regex = '%src="(?!http://)%' I cant figure out what it does. The ? is a greedy quantifier is it not and should be after http://............. or is that rubbish And what does the ! do . Cant find anything info about that.
View Replies !
View Related
For Regex
I want to retrieve full name, city name, state and country from following string: "(Firstname Lastname - Traverse City, MI United States)" I think maybe a regex can be a solution. However I don't have much knowledge on it.
View Replies !
View Related
PHP And Regex
I require little help with PHP regex. I've a whole dump of text: I wanna count occurence of _L_ in it. I did it easily. _L_ is 100 times in it. I wanna get occurence of 'www.example.com' in dump text, if found, stop and return counted value of _L_ like 23rd _L_ or 59th _L_ or 95th _L_ . How can this be done using PHP and regex?
View Replies !
View Related
Chr(0) In Regex
This regex strips links from a website. preg_match_all("/href=["']([^"']+?)["']/i", $contents, $links); It currently works for href="double" and href='single'. I want to make it work for href=nothingbut I can't put ["'chr(0)] for obvious reasons. Can anyone assist me?
View Replies !
View Related
Regex Help
I'm trying to write a regular expression to replace a 'key phrase' with a link IF it's not already inside an <a> tag. For example: ...<a href="link.html">key phrase</a>... doesn't match ...<a href=link.html>here's a key phrase example</a>... doesn't match ...<p>this key phrase isn't in an a tag</p>... does match and i'd like this to be replaced with: ...<p>this <a href="link.html">key phrase</a> isn't in an a tag</p>... One of the tricky parts is matching just the key phrase, not the rest of the text around it. The strings being checked are more than one line and are likely to have many <a> tags already in them.
View Replies !
View Related
Regex W
preg_match('%^[^,.-_!?s][ws,.!?-]+$%', 'test') is passing preg_match('%^[^,.-_!?s][ws,.!?-]+$%', 'tesT') is passing preg_match('%^[^,.-_!?s][ws,.!?-]+$%', 'Test') is not passing w should = [a-zA-Z_] What am i missing?
View Replies !
View Related
Regex For This
I would like to know the regex for the following: input text can contain Quote: alphanumeric characters along with underscore and space for example: "this is user_name". i used the following: PHP Code: /^[a-zA-Z0-9 _]+$/ this works but not perfectly because when the only space bar is pressed it takes the value, i want to prevent this, space should be @ the beginning, what will be the regex for this ?
View Replies !
View Related
Using RegEx
I am trying to write a program that uses regular expressions. I need to search an html document and extract the links. I've tried googling many terms on reg ex, and am unable to find a decent tutorial that will show me how to search the whole document and extract the link information. I want to store it all in a database with an auto increment id for the first field and the url in the second field and the clickable text in the third field. I had found a decent reg ex site a long time ago, but the book mark isn't saved on my pc any more.
View Replies !
View Related
Url Out Of Tag Regex
I'm going batty trying to figure this one out as it seems so simple. I'm trying to retrieve the url (everything between href=" and ">): PHP Code: $string = "lalala this is great: <a href="http://www.google.com"> google </a> blar blar"; $pattern = "http*">"; preg_match($pattern,$string,$matches);
View Replies !
View Related
Use Several Regex
I am making a website with PHP (of course) and have to make this transformation: <l>name</l> to <a href="blabla.php?id=name">name</a> How do I do that? Will I have to use several regex or is it possible that I can use only one?
View Replies !
View Related
Regex URL
I want to prepend all links from a particular domain with a link to my script, such that the link becomes a GET argument to my script. I only want this to do for that particular domain, and leave other domains alone. Here's what I have so far: PHP Code: $search='@<a([^>]+?)href="(.+?)foo.com/(.+?)"(.*?)>(.+?)</a>@si' $replace='<a$1href="myscript.php?fp=$2foo.com/$3"$4>$5</a>' $out=preg_replace($search,$replace,$page_to_parse);
View Replies !
View Related
IP Regex
I'm writing a regex, somehow the regex never matched. after some analyzing it seemed to be the ip-part: <?php $sIP = "192.168.2.1"; if(!ereg('^([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5].){3}([01]?[0-9]{1,2}|2[0-4][0-9]|25[0-5]){1}$',$sIP)) { echo"wrong"; } else { echo"yay..."; } ?>
View Replies !
View Related
Regex Web URL
I am having problems with this regex. I thought I was doing so well this evening writting them with no errors, then poof. PHP Code: $web_url = "www.spechal.com/v4"; if(!eregi("^(www.)?(.*)+[.A-Za-z]+[/]*$", $web_url)) Â Â Â Â Â $err[] = "Error: Web URL is in an invalid format. (www.spechal.com)"; if(!preg_match("#/#", $web_url)) Â Â Â Â Â $web_url .= '/'
View Replies !
View Related
|