PHP - Invoke [
Hi guys I am putting together an array in PHP for encoding into JSON but how do I make it be like
"date": [ and not "date": { ?? Not sure even what to call it or look into. Thanks Similar TutorialsHello,
I need to create a variable that also has a function when invoked, much like the OOP __invoke magic method, but with a variable rather than a class object.
#1: Is this possible?
Consider the situation:
$parent->child->variable = "test";
I also want to run a SQL query using $parent->child->variable('= 2'); where this function would look like
function $this->variable($params) {
return mysql_query('SELECT FROM `parent`.`child` WHERE `variable`' . $params);
}
I already know about safety, etc., so I don't need help on that front. I just need to know if a variable can also be used as a function via its own __invoke magic method or something similar?
hello everybody! This is just basic script, where i try to modify for the needs. I try to play with it. i want to parse some data. The whole script has three parts: 1. Fetching 2. parsing 3. storing i want to put all into one script: Two are allready put together - there all seems to be clear... So this thread is one that asks for the combining two parts of a script - how to invoke a variable between them What has happened untill now: 1st i need to have a connection to database lets say MySQL. I will suggest to use mysqli instead of mysql. Well - okay i safe this db.php $host="localhost"; //database hostname $username="******"; //database username $password="******"; //database password $database="******"; //database name ?> Now i am going to take a new script and save this config.php <?php require_once('db.php'); //call db.php $connect=mysqli_connect($host,$username,$password); //connect to mysql through mysqli if(!$connect){ die("Cannot connect to host, please try later."); //throw error if any problem } else { $select_db=mysqli_select_db($database); //select database if(!$select_db){ die("Site Database is down at the moment, Please check later. We will be back shortly."); // error if cannot connect to database or db does not exist } } ?> Now i have to take care for the script, that takes the files (note this is very basic - it is only a proof of concept. In the real situation i will take cURL since cURL is much much nicer and more elegant and faster etc. <?php require_once('config.php'); // call config.php for db connection $content = file_get_contents("<-here the path to the file goes in-> Position XY! an URL is here "); var_dump($content); $pattern = '/<td>(.*?)<\/td>/si'; preg_match_all($pattern,$content,$matches); foreach ($matches[1] as $match) { $match = strip_tags($match); $match = trim($match); var_dump($match); $sql = mysqli_query("insert into tablename(contents) values ('$match')"); } ?> Note: This is just basic script, where you can modify it for your taste and can play with it. Question: If i have stored the URLs that i want to parse in a local file - how do i "call" them in the script. How do i do the call to file where the URLs (there are more than 2500 URLs that have to be parsed) at the following position: $content = file_get_contents("<-here the path to the file goes in-> Position XY! an URL is here "); The folder with the URLs is stored in the same folder as the scripts reside! Many thanks for all hints and for a starting point! if i have to write more - or if you need more infos - or if i have to be more concrete, just let me know! i love to hear from you! db1 Hi , I am tring to call user define function of java which parse xsl & xml and executing it using php but it is giving me following error. Versions i am using JDK 1.5,Php 5.3,JavaBridge. Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[o:PhpJBridge]]->XMLXSL((o:String)[o:String], (o:String)[o:String]). Cause: javax.xml.transform.TransformerConfigurationExcep tion: Could not compile stylesheet VM: 1.5.0_18@http://java.sun.com/" at: #-12 com.sun.org.apache.xalan.internal.xsltc.trax.Tran sformerFactoryImpl.newTemplates(Unknown Source) #-11 com.sun.org.apache.xalan.internal.xsltc.trax.Tran sformerFactoryImpl.newTransformer(Unknown Source) #-10 PhpJBridge.XMLXSL(SaxonTest.java:88) #-9 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) #-8 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) #-7 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) #-6 java.lang.reflect.Method.invoke(Unknown Source) #-5 php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1049) #-4 php.java.bridge.Request.handleRequest(Request.java:415) #-3 php.java.bridge.Request.handleRequests(Request.java:491) #-2 php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) #-1 p in http://localhost:8080/EchoServer/java/Java.inc on line 117 I have a PHP file in /var/www/html/ called foobar.php with the following content: Quote
<?php
I set the permissions of the foobar.php file to different settings. I set the owner and group of foobar.php and /tmp/output to different values. I tried modifying the httpd.conf file. When I placed this stanza in the httpd.conf file QuoteLoadModule php7_module /usr/lib64/httpd/modules/libphp7.so I could not restart the httpd service. I tried using just QuoteLoadModule php7_module modules/libphp7.so But this failed too. I thought PHP would interpret the file regardless of how I access it (e.g., via a web page and with the php command from a Linux terminal). How do I get PHP to invoke a Bash command when someone visits a .php web page? |