PHP - String Concatenation With Php - A Newbie-question For A Little Parser With Curl
Hello dear folks i am currently workin on a little parser with cURL - and i have some questions he How to do the String concatenation with PHP ; note i wanna do it with curl! the target URL: http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=572.8745475728288 click all checkbuttons Results: approx 6400 results Here i can provide some "more help for getting the target!" - btw see three detail page: http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=261.2855969084779&SchulAdresseMapDO=116191 http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=261.2855969084779&SchulAdresseMapDO=116270 http://www.schulministerium.nrw.de/BP/SchuleSuchen?action=261.2855969084779&SchulAdresseMapDO=188268 btw: we can loop over the results - with a iteration - especially i wanna know: how to do the String concatenation with PHP ; note i wanna do it with curl! function get_page_data($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); if($output!=false && $_POST['dt']=='No') return $output; curl_close($ch); } for($i=1;$i<=$match[1];$i++) { $url = "http://www.example.com/page?page={$i}"; $data = get_page_data($url); if($data) { $cleaned = string_between('onload="check();">', '</body>', $data); return = stip_tags($cleaned, '<table><tr><td><div>'); } } any and all help will be greatly appreciated love to hear from you best regards Similar Tutorialsi want to do it with cURL-Multi since this is the most pretty way to do it! Well i am not sure bout the string concatenation. How to do it - Note i want to fetch several hundred pages: see the some details for this target-server sites - /(i have to create a loop over several hundred sites) siteone_dot_com?show_subsite=9009 siteone_dot_com?show_subsite=9742 siteone_dot_com?show_subsite=9871 and so on and so fort how to appy this loop into the array of the curl-multi <?php /************************************\ * Multi interface in PHP with curl * * Requires PHP 5.0, Apache 2.0 and * * Curl * ************************************* * Writen By Cyborg 19671897 * * Bugfixed by Jeremy Ellman * \***********************************/ $urls = array( "siteone", "sitetwo ", "sitethree" ); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); print_r($res); ?> Hi - good evening! thanks for the answer and all the help so far Oncemore the "Fetching-part" for a little parser-script: Here we go - new target urls: see the overview: http://dms-schule.bildung.hessen.de/index.html http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html Search by pressing the button "type" and then choose all schools with the mouse! Results 2400 schools: Here i can provide some "more help for getting the target!" - btw: see some details for this target-server: http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=9009 http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=9742 http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=9871 well - you see i have to iterate over the sites - with a function /(a loop) http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=1000 to 10000 BTW - after fetching the page i have to see which one are empty - those ones do not need to be parsed! Well - i want to do this with curl-multi since this is the most advanced way to do this: I see i have an array that can be filled I have to try it out...!! Well, I'm not pretty sure - but judging by the low level of PHP i have: I think that i may need a double array to define the URLs like: Can i do like so?: $urls = array( "siteone" => "suche_schul_db.html?show_school=%i", "sitetwo" => "suche_schul_db.html?show_school=%i", "sitethree" =>"suche_schul_db.html?show_school=%i" ); $params = array ( for ($i = 1; $i <= 10000; $i++) { // body of loop } // well i have to define the variables in a open form like abvove nand not below: // better than doing it like so: "siteone" => array(9009, 9742, 9871), ); then pass them to curl-multi as: foreach ($urls as $id => $url) { foreach ($params[$id] as => $param) { $i = $id . $param; $finalurl = sprintf($url, $param); $conn[$i] = curl_init($finalurl); I don't know if that's fits the needs tip that i am looking for but I hope so ;-) Can i do like so [see above]? What do yu think. i send you many greetings martin May I please ask one more question? About replacing a string only if it appears *after* a particular string?
I'm having trouble replacing all occurrences of "wheel" with "TIRE" but only when the word "wheel" is after this: (W/
Example:
From this:
A large wheel is shiny.
Big 4 wheel truck (W/ wheel)
Car with a wheel, and a small toy (w/ wheel)
Four wheelers are cool
To this:
A large wheel is shiny.
Big 4 wheel truck (W/ TIRE)
Car with a wheel, and a small toy (w/ TIRE)
Four wheelers are cool
Unfortunately, I thought this worked:
$fixed = str_ireplace('wheel','tire',substr($original_string,stripos($original_string,'(W')));
...until I realized it was *cutting off* all characters up until that first '(W/'
What can be done to make this work?
Edited by Nyla, 20 November 2014 - 09:40 PM. I am using the code posted here to do something with a third party software
http://www.interwork...trusted-tickets
however its utterly frutrating that something as simple as
$fullUrl = "http://{$server}/trusted/{$ticket}/{$url}";
returns me the following
moOaH6BAKFMGGszd_IQHTvpAhttp://<server>/trusted/1/views/<dashboard>?format=png
instead of
http://<server>/trusted/moOaH6BAKFMGGszd_IQHTvpA/views/<dashboard>?format=png
completely beats me. Any idea why ? Is it something to do with the variable $ticket which has the value of moOaH6BAKFMGGszd_IQHTvpA in this case ?
I am trying to figure out how to have an if statement in the middle of strings I am trying to concatenate. I have a from that has a address1 and address2, where address2 often does not exist. So I want to only add that line if there is actually content. I was trying something like the following, but that is giving me an error. I am pretty new to php, so I can't seem figure it out. Any help would be greatly appreciated. Code: [Select] "<p><strong>Address 1: </strong><br>" . $address1 . "<br>" if ( isset($address2) ) { echo . $address2 . "<br>" } . $city . ", " . $state . " " . $zip . "</p>" Code: [Select] <?php $dom = new DOMDocument(); $dom->loadHTMLFile('http://en.wikipedia.org/wiki/Liverpool_F.C.'); $domxpath = new DOMXPath($dom); foreach ($domxpath->query('//span[@id="Players"]/../following-sibling::table[1]//span[@class="fn"]') as $a) {echo " <p>$a->textContent</p> "; }; ?> Hello, how can I parse an XML that includes all of the $a->textContent with a tag like <player></player>? hello dear Freaks
i am currently musing bout the portover of a python bs4 parser to php - working with the simplehtmldom-parser / pr the DOM-selectors... (see below). The project: for a list of meta-data of wordpress-plugins: - approx 50 plugins are of interest! but the challenge is: i want to fetch meta-data of all the existing plugins. What i subsequently want to filter out after the fetch is - those plugins that have the newest timestamp - that are updated (most) recently. It is all aobut acutality... https://wordpress.org/plugins/participants-database ....and so on and so forth.
https://wordpress.org/plugins/wp-job-manager we have the following set of meta-data for each wordpress-plugin: Version: 1.9.5.12 installations: 10,000+ WordPress Version: 5.0 or higher Tested up to: 5.4 PHP Version: 5.6 or higher Tags 3 Tags:databasemembersign-up formvolunteer Last updated: 19 hours ago
the project consits of two parts: the looping-part: (which seems to be pretty straightforward). the parser-part: where i have some issues - see below. I'm trying to loop through an array of URLs and scrape the data below from a list of wordpress-plugins. See my loop below- as a base i think it is good starting point to work from the following target-url:
plugins wordpress.org/plugins/browse/popular with 99 pages of content: cf ...
the Output of text_nodes: ['Version: 1.9.5.12', 'Active installations: 10,000+', 'Tested up to: 5.6 '] but if we want to fetch the data of all the wordpress-plugins and subesquently sort them to show the -let us say - latest 50 updated plugins. This would be a interesting task:
first of all we need to fetch the urls then we fetch the information and have to sort out the newest- the newest timestamp. Ie the plugin that updated most recently List the 50 newest items - that are the 50 plugins that are updated recently ..
we have the following set see here the Soup_ soup = BeautifulSoup(r.content, 'html.parser') target = [item.get_text(strip=True, separator=" ") for item in soup.find( "h3", class_="screen-reader-text").find_next("ul").findAll("li")[:8]] head = [soup.find("h1", class_="plugin-title").text] new = [x for x in target if x.startswith( ("V", "Las", "Ac", "W", "T", "P"))] return head + new with ThreadPoolExecutor(max_workers=50) as executor1: futures1 = [executor1.submit(parser, url) for url in allin] for future in futures1: print(future.result())
see the formal output Quote
background: https://stackoverflow.com/questions/61106309/fetching-multiple-urls-with-beautifulsoup-gathering-meta-data-in-wp-plugins Well - i guess that we c an do this with the simple DOM Parser - here the seclector reference. https://stackoverflow.com/questions/1390568/how-can-i-match-on-an-attribute-that-contains-a-certain-string
look forward to any hint and help.
have a great day Edited May 3, 2020 by dil_bertwhat would be the best code to use to just use curl to reload a url in a loop? Like what all options do I need that would be the fastest? Ive been using Code: [Select] <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.example.com'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_close($ch); ?> I'm trying to automate with php and the form I need to submit has a post call with hidden inputs. How do I mimic a post call to another page with the hidden inputs using curl? The hidden inputs has to be carried over to the next page so I can continue the process though. How do i load a page that is entirely made in javascript i`ve tried to load a page but its not loading it Code: [Select] <td valign="middle"><b id="loadingMessage">Loading...</b></td> its keeps getting stuck at Loading I have FOLLOWLOCATION 1 Code: [Select] $ch = curl_init(); curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" ); curl_setopt( $ch, CURLOPT_URL, $url1 ); curl_setopt( $ch, CURLOPT_COOKIEJAR, $cook ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $ch, CURLOPT_ENCODING, "" ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_AUTOREFERER, true ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout ); curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout ); curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 ); $content = curl_exec( $ch ); $response = curl_getinfo( $ch ); curl_close ( $ch ); echo $content; print_r( $response); how do i load a page that is made in javascript with curl ? or does it have hidden .htm files that are loading through javascript I have a web server which contains a public site and a private site. I want to be able to test for public or private using the page title and return the appropriate header which contains a different banner, css etc. Firstly - the syntax below seems to be incorrect because it doesnt work correctly. More importantly how do I add all the values to an array and than iterate through it to check for a matching page title? Code: [Select] public function publicSite() { if ($this->getTitle()== 'Home' || 'About Us'||'Registration' || 'Sitemap' || 'Contact Us' || 'Useful Links' || 'Feedback') { return true; } return false; } Then later on I would have: Code: [Select] if ($this->publicSite()) { require($ROOT.'interface/pages/publicheader.php'); } else { require($ROOT.'interface/pages/privateheader.php'); } Thanks heaps! Hi there, I am scratching my head for ages trying to get this to work. I am adapting a script that simply outputs a floorplan image from a MySQL database. Only problem is that it outputs the <DIV> and all the title and formatting even if no image exists. I only want to output the <DIV> if an image exists. Thanks in advance for any help. Charlotte Code: [Select] <div id="property-contact"> <h2 id="h2-section" class="h2-section"><?php _e('Floor Plan',TS_DOMAIN) ?></h2> <div class="box2 clearfix"> <?php $floor_plans_image_id =get_post_meta($post->ID, "_thumbnail_id", true); $myrows = $wpdb->get_results( "SELECT guid FROM wp_posts WHERE ID=".$floor_plans_image_id ); ?> <a href="<?=$myrows[0]->guid?>" rel="prettyPhoto[gallery]"><img src="<?=$myrows[0]->guid?>" width="250px;"/></a> </div><!-- end box3 --> </div> Hye there im branded new in php here. Im trying to develop a system based on php and mysql. I have 20 fields on my database table. Im trying to separate fields into 2 forms which is each form contain 10 fields - form_1.php(contain 10 fields) -form_2.php(contain 10 fields) form_1.php and form_2.php is connected each other which is user have to insert data in the form_1.php and then there are NEXT button that will bring user to form_2.php.In the form_2.php there will be a SUBMIT button which send data to database. Im trying to do but i cannot go through can someone show me any way to ?? hi I'm a newbie in php and I came across this Code: [Select] if($_SERVER['REQUEST_METHOD'] == 'POST'){ and this Code: [Select] $_POST = $this->_params; I know this might be a stupid question but can you please tell me what they are Hi I'm trying to insert some information into my database but it tells me that the name is undefined how to I define it so that it works. Here is my code Code: [Select] <html> <body> <form action="insert.php" method="post"> name: <input type="text" name="name" /> email: <input type="text" name="email" /> password: <input type="text" name="password" /> <input type="submit" /> </form> </body> </html> <?php $link = mysql_connect('localhost','test',''); if (!$link) { die('Could not connect to MySQL: ' . mysql_error()); } mysql_close($link); $sql="INSERT INTO emails (name,email, password) VALUES ('$_POST[name]','$_POST[email]','$_POST[password]')"; mysql_close($con) ?> After looking around the net and getting i feel close i though i would post and ask you all. I am trying to add x number of names to a database each on its own row. I found some code and have edited it and i understand most of what its doing but i cannot get it to work, it just add witch ever name was last. Here is the form code just with 3 test fields. Quote <form id="form1" name="form1" method="post" action="addplayer2.php"> <p> <input name="player[]" type="text" id="player[]" size="15" /> </p> <p> <input name="player[]" type="text" id="player[]" size="15" /> </p> <p> <input name="player[]" type="text" id="player[]" size="15" /> </p> <input type="submit" name="submit" id="submit" value="Submit" /> </form> Ok this the script i found in it unedited state, i thought i would be easy to understand if you saw it before i broke it. I tried changing the word Activity to player and the work Act to play and then changing all other referanced. Quote <?php $con = mysql_connect("localhost","Application","*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("CpaApp", $con); foreach($_POST['Activity'] as $row=>$Act) { $Activity=$Act; // why does this not have post? Or is it using the one above? $Position=$_POST['Position'][$row]; $StartDate=$_POST['StartDate'][$row]; $EndDate=$_POST['EndDate'][$row]; } //enter rows into database foreach($_POST['Activity'] as $row=>$Act) { $Activity=mysql_real_escape_string($Act); // Same question why no $_POST? does it use the one above? $Position=mysql_real_escape_string($_POST['Position'][$row]); $StartDate=mysql_real_escape_string($_POST['StartDate'][$row]); $EndDate=mysql_real_escape_string($_POST['EndDate'][$row]); } $involv = "INSERT INTO Involvement (Activity, Position, StartDate, EndDate) VALUES ('.$Activity.','.$Position.','.$StartDate.','.$EndDate.')"; if (!mysql_query($involv,$con)) { die('Error: ' . mysql_error()); } echo "$row record added"; mysql_close($con) ?> On filling out the fields with name lets say Paul Bill and Jack it echos that it has added x number of rows but when looking in the database it has only added the last in this case Jack. If there is anyone willing to edit the code above so it will work with my single field i would be very great full, also if someone would answer the questions i placed in the script that would be great also. Many thanks. Lister471 Hi, I'm REALLY new to PHP, so any help would be appreciated . I'm trying to make a script that truncates a post after a certain amount of words (Below). And I suppose the article would have to have $description="blahblahblah";. My question is; how would I go about making this script actually work? Where would I put the code and the articles? Like I said, I have less than 2 days experience with PHP, so please don't judge Code: [Select] // this signifies how to truncate function myTruncate($string, $limit, $break=".", $pad="...") { // return with no change if string is shorter than $limit if(strlen($string) <= $limit) return $string; // is $break present between $limit and the end of the string? if(false !== ($breakpoint = strpos($string, $break, $limit))) { if($breakpoint < strlen($string) - 1) { $string = substr($string, 0, $breakpoint) . $pad; } } return $string; } And the code that says when to truncate: Code: [Select] // replace 'xxx' with the number desired $shortdesc = myTruncate($description, XXX); echo "<p>$shortdesc</p>"; I'm just learning PHP as a first language so you'll probably see my around here quite a bit! I'm completely baffled at why this isn't working and after about 30 minutes of frustration I decided to seek some help lol. Code: [Select] require '/opt/lampp/htdocs/PHP/Chapter 3/scripts/app_config.php'; //database connection code if (mysql_connect($db_host, $username, $password) != false) { mysql_select_db("db_name"); echo "MySQL Database Selected"; } else { echo "Error connecting to database"; } app_config.php Code: [Select] <php // Database Connection Constants $db_host = ""; $username = ""; $password = ""; $db_name = "chp3"; ?> results: Notice: Undefined variable: db_host in /opt/lampp/htdocs/PHP/Chapter 3/scripts/connect.php on line 6 Notice: Undefined variable: username in /opt/lampp/htdocs/PHP/Chapter 3/scripts/connect.php on line 6 Notice: Undefined variable: password in /opt/lampp/htdocs/PHP/Chapter 3/scripts/connect.php on line 6 Any help is appreciated. Hello, I'm sorry, I know nothing about php programming but need some help - I'm sure this will be a simple question! I have created a Formidable form on Wordpress (form is named BookingTest). It has a drop down box on (called dropdown) that has a list of numbers that requires a unique value. The plugin designers have shared some code that is supposed to remove used values from the drop down box but it's not working - I don't know if I've put it in the right place or if I need to edit it or anything like that. This is there documentation: https://formidableforms.com/knowledgebase/frm_setup_new_fields_vars/?fbclid=IwAR1Zj1jWo6iqdR4Cjq8MGpTLRW01XToPR7vp_2oN4XEmQ81SLAW-sbtbYKU#kb-remove-used-options I have pasted this code in it's entirety to a Code Snippets plugin but I still get all the values appear. Do I need to amend it to refer to my form explicitly? How is this filter called? Do I need to add an action?! Really confused :( Thank you! |