-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
so what are you saying, you don't know how to change all the double quotes to single quotes?
-
Finding a specific pattern of numbers in body content
.josh replied to n1concepts's topic in Regex Help
preg_match('~[0-9]+\s*-\s*[0-9]+\s*-\s*[0-9]+\s*-\s*[0-9]+~',$content,$match); -
Display all databases in dropdown menu.
.josh replied to prathameshkakade's topic in PHP Coding Help
you already looped through the results once, so first you need to reset the internal pointer: mysqli_data_seek($result,0); Then you need to loop through it same way as before -
And I want a pony. I feel like we've had this conversation before.
-
I want a pony.
-
well for starters you are improperly quoting things. You use double quotes as your outermost delimiter for the $out[body] string and then proceed to liberally use double quotes in the value without escaping them, so php thinks you are closing the string. You need to either a) escape all of the double quotes (except the starting and ending quotes for the actual variable) b) change the double quotes to single quotes (except the starting and ending quotes) c) use HEREDOC syntax for the variable so you don't have to worry about quotes.
-
it depends on how they present the data. You may be able to get away with using cURL to login and retrieve a page listing the data you want, and then use regex (ref.pcre) or DOM to pull the data from the page content. But usually people don't like others scraping their content so they may do something like use javascript to load content separately so that that it won't render the content if you try to use those functions. You can attempt to request the content url directly and maybe that will work, but you may have to fake or get around a token system or something. Or they could be rendering the data through flash, in which case you're kinda SoL. Not impossible but usually more trouble than its worth to setup.
-
if you have control over the external file, you should change the format to be JSON, or else serialize the data, so that you can more easily parse it.
-
check my posted code again, the one you quoted in your post has one of the single/double quotes wrong
-
not a sql expert but here's one way to do it... $srcquery = str_replace(" ","|",$_REQUEST['srcquery']); $query = "SELECT COUNT(*) as num FROM $tableName WHERE customerName REGEXP '".$srcquery."' OR homePhone REGEXP '".$srcquery."' OR comments REGEXP '".$srcquery."' AND agent = '".$logged."' ORDER BY id DESC"; one thing to note here though is you really should look into sanitizing user input before using it in a query. Google sql injection.
-
Does your club have secret decoder rings?
-
well, the + prefix is a shortcut. You could have alternatively done tbox$count.value = parseInt(change$count)+1000;or even tbox$count.value = Number(change$count)+1000;The overall takeaway here is that wherever you got change$count from (e.g. grabbing from some form field, receiving an ajax response, etc.), the value was stored as some other type (probably string). So you were basically doing "100"+1000 which javascript interprets as string concatenation. So there are ways (shown above) to convert the value to another variable type (type casting), in order to ensure javascript does what you expect it to do. It is actually one of those best things to check (you can use the typeof operator to check variable type) and/or convert variable type before performing operations, to ensure expected results.
-
well in any case, these are the values I used, based on the context of your posts: $searchterm="provision+of+European"; $currentpagenumber='1'; $file_string = file_get_contents('http://www.emeraldinsight.com/search.htm?st1='.$searchterm.'&ec=1&bf=1&ct=jnl&nolog=503574&displayno=30&page='.$currentpagenumber.''); preg_match_all('#<span class=\"header\">(.*?)</span>#s', $file_string, $titles); if( count($titles[1]) > 0) { for($i = 0; $i < count($titles[1]); $i++) { echo "my count".$i." contains : ".$titles[1][$i]."<br>"; } } and here are the results: my count0 contains : European information: the pattern of provision in Scotland my count1 contains : The provision of European information by public libraries in the UK my count2 contains : The provision of European information to the academic community in university libraries: a case study of a European Documentation Centre my count3 contains : Problems, needs and service provision related to stimulant use in European prisons my count4 contains : Can Pension Systems Cope? Population Ageing and Retirement Income Provision in the European Union my count5 contains : The European information needs of secondary school teachers in Scotland: recent developments in the provision of information to schools and colleges my count6 contains : The pattern of provision of European Union information in France and the United Kingdom: a comparative study of services my count7 contains : Methodological problems of sampling young homeless people in four European societies with different levels of service provision and definitions of homelessness my count8 contains : Electronic public information and Europe: an electronic forum in support of transparency and openness in government my count9 contains : Real estate education in Europe: some perspectives on a decade of rapid change my count10 contains : Strategic development related to the Europeanization of UK logistics and distribution service suppliers my count11 contains : User involvement in the illegal drugs field: what can Britain learn from European experiences? my count12 contains : Multi-racial Provision: An Integral Part of Library and Information Services my count13 contains : European vocational education and training: a prerequisite for mobility? my count14 contains : Commonplaces my count15 contains : Central and Eastern European business information: a review my count16 contains : Central and Eastern European business information: a review my count17 contains : New Challenges in Training my count18 contains : Training for Europe – Should Britain Follow the German Model? my count19 contains : Reluctant enablers: Competition in local government in Ireland and the UK my count20 contains : Trade unions and the training of health and safety representatives: Challenges of the 1990s my count21 contains : European Union Enterprise Policy and the Hospitality Industry my count22 contains : The implementation of the European Credit Transfer system as a curriculum evaluation tool my count23 contains : HRD in Europe my count24 contains : The provision of psychotherapy: an international comparison my count25 contains : Aslib open meeting: Euronet and you my count26 contains : Forwarders and Computers: More Evidence for Regulation? my count27 contains : Continuing vocational training in Europe my count28 contains : Food and residential care in old age my count29 contains : The Role of the European Community in Civil and Environmental Emergencies so my guess is either your $searchterm and $currentpagenumber don't have expected values, or your problem is elsewhere.
-
what are the values of $searchterm and $currentpagenumber
-
lookahead condition Pattern example: (?=12)[0-9]{3} Goal is to match for a 3 digit number that starts with "12". The lookahead first checks to see if there's a "12". If there is, then proceed to match 3 digits. Example 1: 3 digit number matched: $string = "123"; preg_match("~(?=12)[0-9]{3}~",$string,$match); print_r($match);Output: Array ( [0] => 123 ) Example 2: 3 digit number not matched: $string = "193"; preg_match("~(?=12)[0-9]{3}~",$string,$match); print_r($match);Output: Array Array ( ) The main thing to note about lookaheads and lookbehinds is that they do not actually consume anything. Normally each time something is matched in a string, that part of the string is consumed, meaning the regex engine's pointer moves on to the next character to try and match something. lookaheads/behinds do not make the pointer move. It peeks ahead (or behind) but stays in the same place. lookbehind condition Same thing as lookahead, except for looking back. Pattern example: (?<=foo)bar Match "bar" only if it was preceded by "foo". Example 1: "bar" is preceded by "foo": $string = "foobar"; preg_match("~(?<=foo)bar~",$string,$match); print_r($match);Output: Array ( [0] => bar ) Example 2: "bar} is not preceded by "foo": $string = "fubar"; preg_match("~(?<=foo)bar~",$string,$match); print_r($match);Output: Array ( )
-
back reference condition Pattern example: (something )?((?(1)foo|fu)bar) Pattern first looks for "something ". Then comes the back reference condition. If it exists, match for "foo". If it does not exist, match for "fu". Then match for "bar". Whole thing is wrapped in a group (2) to illustrate results easier. Example 1: back reference #1 matched: $string = "something foobar fubar"; preg_match("~(something )?((?(1)foo|fu)bar)~",$string,$match); print_r($match); Output: Array ( [0] => something foobar [1] => something [2] => foobar ) Example 2: back reference #1 not matched: $string = "foobar fubar"; preg_match("~(something )?((?(1)foo|fu)bar)~",$string,$match); print_r($match); Output: Array ( [0] => fubar [1] => [2] => fubar )
-
dalecosp: If they were turned off, he wouldn't have gotten the "could not connect" message. samuz: you answered your own question: the remote host blocked the request from the server your script was running on. It's possible the server's IP just happened to get caught up in some other range blacklisted by some filter (bot/spam prevention) but it's more likely the server's IP does have a history of being used by spammers/botters.
-
How to find 2 or more words in a string with preg_match?
.josh replied to noidea's topic in Regex Help
@irate: The issue with your solution is that you had two preg_matches in the condition. But the point he made about that was that there are a variable amount of keywords to preg_match. It might be just 1, or it might be 10. Look at his code; it explodes a string at the spaces. So, the only way to make your solution scalable is to build the condition as a string and then eval it, which isn't a good thing to do. That is why I showed how to keep the condition as a single preg_match by looping through the keywords.- 13 replies
-
- preg_match
- search
-
(and 1 more)
Tagged with:
-
How to find 2 or more words in a string with preg_match?
.josh replied to noidea's topic in Regex Help
put the search strings into an array and loop through them. $searchTerms = array('foo','bar'); $allMatched = true; foreach ($searchTerms as $searchTerm) { if ( preg_match('~'.$searchTerm.'~',$text_to_search) == false ) { $allMatched = false; break; } }- 13 replies
-
- preg_match
- search
-
(and 1 more)
Tagged with:
-
okay, then $shipping is probably an associative array (named keys), not numeric (numbered keys). do this: print_r($shipping); What do you get? If it's an associative array then you will need to use foreach to loop through the array. foreach ($shipping as $key => $value) { echo $value. "<br/>"; }
-
echo "name='" . $image->alttext ."' options_name='Size' options='8x6:9.50;10x8:13.50' qty_field = 'true' b_title='Add To Basket'";
-
$shipping['$desdecero'] should be $shipping[$desdecero] variables will be parsed inside double quotes, but not single quotes. But you shouldn't really put it in quotes to begin with, as it is less efficient.
-
I'm not really seeing any compelling reason why you should even use a linux distro. Sounds like you should just stick with Windows and change the theme when you get tired of it.
-
Adding isset() causes database value to be ignored
.josh replied to ICYUH8's topic in PHP Coding Help
Yes, that's exactly what I meant. It should be if(isset($settings['set_payment']) && $settings['set_payment']=='Y') { Well..it depends on what the intentions of your code are.. for example, in the 2nd block of code I posted, with those custom error messages.. if all of the conditions were the same, only difference was the error message, you could refactor that code by putting the error messages in an associative array, where the indexes match the $_POST index. Then you could just loop through the array with a foreach loop and have a single condition inside the loop, and the index would be popped with the current $key in the loop. Alternatively, you could make an array of all your expected stuff and set default values for them. But you'd have to refactor your code to work with the default values.