85 Answered Questions for the topic PHP
Php
05/30/19
How to find the foreach index?
Is it possible to find the `foreach` index?
in a `for` loop as follows:
for ($i = 0; $i < 10; ++$i) {
echo $i . ' ';
}
`$i` will give you the index.
Do I have to use the `for` loop...
more
Php
05/29/19
Insert new item in array on any position in PHP?
How can I insert a new item into an array on any position, for example in the middle of array?
How to parse a string of boolean logic in PHP?
I'm building a PHP class with a private member function that returns a string value such as:
'true && true || false'
to a public member function. (This string is the result of some regex...
more
Php
05/28/19
What is thread safe or non-thread safe in PHP?
I saw different binaries for PHP, like non-thread or thread safe? What does this mean? What is the difference between these packages?
Php
05/28/19
Pass a PHP string to a JavaScript variable (and escape newlines)?
What is the easiest way to encode a PHP string for output to a JavaScript variable?
I have a PHP string which includes quotes and newlines. I need the contents of this string to be put into a...
more
Php
05/28/19
How can one use multi threading in PHP applications?
Is there a realistic way of implementing a multi-threaded model in PHP whether truly, or just simulating it. Some time back it was suggested that you could force the operating system to load...
more
Php
05/28/19
Convert PHP object to associative array?
I'm integrating an API to my website which works with data stored in objects while my code is written using arrays.
I'd like a quick and dirty function to convert an object to an array.
Php
05/28/19
Get the full URL in PHP?
I use this code to get the full URL:
$actual_link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
The problem is that I use some masks in my `.htaccess`, so what we see in the URL is...
more
Php
05/28/19
Why would one omit the close tag?
I keep reading it is poor practice to use the PHP close tag `?>` at the end of the file. The header problem seems irrelevant in the following context (and this is the only good argument so far):...
more
Php
05/28/19
How do I catch a PHP Fatal Error?
I can use `set_error_handler()` to catch most PHP errors, but it doesn't work for fatal (`E_ERROR`) errors, such as calling a function that doesn't exist. Is there another way to catch these...
more
05/28/19
What is the point of interfaces in PHP?
Interfaces allow you to create code which defines the methods of classes that implement it. You cannot however add any code to those methods. Abstract classes allow you to do the same thing, along...
more
Php
05/28/19
How do I send a POST request with PHP?
Actually I want to read the contents that come after the search query, when it is done. The problem is that the URL only accepts `POST` methods, and it does not take any action with `GET`...
more
Php
05/27/19
Send email using the GMail SMTP server from a PHP page?
I am trying to send an email via GMail's SMTP server from a PHP page, but I get this error:
> authentication failure [SMTP: SMTP server does no support authentication (code: 250, response:...
more
Php
05/26/19
Fastest way to check if a string is JSON in PHP?
I need a really, really fast method of checking if a string is JSON or not. I feel like this is not the best way:
function isJson($string) {
return ((is_string($string) &&
...
more
Php
05/26/19
Is there an easy way to delete an element from an array using PHP?
Is there an easy way to delete an element from an array using PHP, such that `foreach ($array)` no longer includes that element?
I thought that setting it to `null` would do it, but apparently it...
more
05/24/19
How would you access Object properties from within an object method?
What is the "purist" or "correct" way to access an object's properties from within an object method that is not a getter/setter method?I know that from outside of the object you should use a...
more
Php
05/22/19
How to enable PHP short tags?
I have a web application on a Linux server which starts with `<?`
I needed to copy this application to a windows environment and everything is working fine except that an SQL statement is being...
more
Php
05/22/19
What is the difference between client-side and server-side programming?
I have this code:
<script type="text/javascript">
var foo = 'bar';
<?php
file_put_contents('foo.txt', ' + foo + ');
?>
var baz = <?php echo 42; ?>;
...
more
Php
05/22/19
PHP + curl, HTTP POST sample code?
Can anyone show me how to do a php curl with an HTTP POST?
I want to send data like this:
username=user1, password=passuser1, gender=1
To `www.domain.com`
I expect the curl to return a...
more
Php
05/21/19
What is the difference between single-quoted and double-quoted strings in PHP?
I'm not an expert in PHP programming, but I'm a little confused why I see some code in PHP with string placed in single quotes and sometimes in double quotes.
I just know in .NET, or the C...
more
AngularJS and PHP backend?
Maybe it's not a real question, rather is's a *discussion*. I decided to learn angular, using a simple task, build a blog system. And i have a few questions.
Lest imagine that the php app will...
more
Php
05/20/19
When to use self over $this?
In PHP 5, what is the difference between using `self` and `$this`?
When is each appropriate?
Php
05/20/19
PHP random string generator?
I'm trying to create a randomized string in PHP, and I get absolutely no output with this:
<?php
function RandomString()
{
$characters =...
more
Php
05/18/19
How to convert date to timestamp in PHP?
How do I get timestamp from e.g. `22-09-2008`?
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.