I tried this but only got a syntax error:
<?php
$a = true;
$str = <<< EOF
{$a ? 1 : 2}
EOF;
echo $str;
Is it possible to use such kind of conditional statement inside heredoc?
<?php
function register_template(){
print_r(func_get_args());
# the result was an array ( [0] => my template [1] => screenshot.png [2] => nice template .. )
}
register_template( # unkown number of arguments
$name = "my template",
$screenshot = "screenshot.png",
$description = "nice template .. "
)
?>
BUT , I want the result array as $key = $value form , $key represents the parameter name.
<?
if($id == 2) {
?>
html goes here
<?
}
else {
?>
if id is not 2 then something goes here
<?
}
?>
How can I write php+html in one file more beautiful without learning smarty?
I have a directory that will be getting updated frequently, I want to display the last four images files uploaded, which match a certain pattern, on my php page.
Is this possible without having to perform a sort on every single image within the directory?
Many thanks!
Hi
I need to know how to get the first n words from text stored in my DB in PHP?
for example if there is some text in my DB like this one :
"word1 word2 word3 word4 text one test four five"
How I can get the first 4 or five words from this text?
Thnks in Advance.
I wrote a html scraper to scrape my various social identites, so I can make a real time 'biography' website.
However after using php curl_exec, I find that texts that I have quoted, end up being formatted in a weird character set.
ex: "I love dogs" gets formatted to ’I love dogs ’
"I hate cheese" gets formatted to “I hate cheese�
How do I either scrub these characters, or set curl not to format quotes like this.
Also, I have turned off magic_quotes.
I have a string which contains only numbers. Now I want to remove all leading 0s from that string
For example:
input: 000000001230
output: 1230
input: 01000
output: 1000
Is there any function in PHP/Zend for this?
Thanks
I have a PHP script on a webserver.
This file is invoked via the shell by another program but it could still be run by the webserver in response to an HTTP request.
How can the script determine the way it was invoked?
I need to return a JSON encoded response to a flash http get request.
In ASP.NET, I do this with a ASHX handler.
What's the PHP equivalent ?
I mean in order that I only get JSON back, and not the <html> etc.
I am thinking about setting the
php.ini, my.cnf and httpd.conf default charsets=UTF-8
The website is in swedish lang only.
I have some folders with special chars in them, also some files.
Is there any harm by doing this?
Is it cross-browser safe?
Thanks
I am trying to set up automated .htaccess updating. This clearly needs to be as secure as possible, however right now the best I can do file permission-wise is 666.
What can I do to setup either my server or php code so that my script's fwrite() command will work with 644 or better? For instance is there a way to set my script(s) to run as owner?
Traits have been one of the biggest additions for PHP 5.4. I know the synatax and understand the idea behind traits, like horizontal code re-usage for common stuff like logging, security, caching etc.
However, I still dont know yet how I would make use of traits in my projects.
Are there any open source projects that already use traits? Any good articles/reading material on how to structure architectures using traits?
Which PHP framework should I choose between ZendFramework or YII?
Points I need to consider:
Performance (assuming an accelerator is used)
Documentation
stability of framework
less to code.
How to transfer json data to html with php?
$url="http://api.nytimes.com/svc/search/v1/article?format=json&query=usa&rank=newest&api-key=mykey"
when I type the url in browser, it return
{"offset" : "0" , "results" : [{"body" : "A guide to cultural and recreational goings-on in and around the Hudson Valley. ...}]}
how to put the json body data into html? I mean like this echo '<div class="body"></div>';
In some languages (ColdFusion comes to mind), you can run a query on the result set from a previous query. Is it possible to do something like that in php (with MySQL as the database)?
I sort of want to do:
$rs1 = do_query( "SELECT * FROM animals WHERE type = 'fish'" );
$rs2 = do_query( "SELECT * FROM rs1 WHERE name = 'trout'" );
How to include an image inside another image in PHP? I want to do it like in twitterbackgrounds.com personalized backgroud. there is one main image and we can upload four personal images after that it will show as watermark of the main image.
Hello All
I am looking to write an extremely simple "contact us" form that will email the response to me. My two technologies are PERL and PHP. What I am wondering is, which technology is more secure? Any and all opinions will be appreciated.
Thanks for reading, and have a great day.
I need to find a certain key in a pdf file. As far as I know the only way to do that is to interpret a pdf as txt file. I want to do this in PHP without installing a addon/framework/etc.
Thanks
Hi I have to flip a thumpnail image before merge it with another jpeg file. but when I rotate 45 degree using php. It shows a black background. how can I avoid that. any body can help me.
Most of the applications that I'm finding, inncluding LiveHelp and PHP Live Chat! feature terrible, un-commented, non-cross-browser compatible Javascript.
I'm looking for chat software that uses a Javascript framework to avoid some persistent and common bugs related to the DOM.
I am using combination of php+jQuery for captcha validation and later sending mails and do other stuff. The pseudo code is something like this:
captcha_code = jQuery.post(.....execute captcha script and get status)
if(captcha_code == "correct"){
send_mail_using_php_script;
}
Now I have no idea whether spammers can directly execute the "send_mail_using_php_script". Do they? If yes, then shall I move captcha validation in send_mail_using_php_script to make it more safer? Is there any other safer method?
Prashant
I have a step 1 page, and a step 2 page. I want to take the information from step 1 page, then step 2 page, and save as session information (which i have already done). Once this information is all gathered i then want to be able to submit it to another php page using HTTP POST.