I have an upload script that runs on a windows webserver 2008. The uploads works nice, the file is created on the server. But when I try to access the uploaded image file via http, I just get an error 401. How can I resolve this? EDIT: setting the chmod to 0777 after the file has been uploaded did not
Tag: php
Can’t add new lines in JavaScript alert Box?
I’m generating a string in PHP and then eventually passing this string into a JavaScript alert box, my problem is I actually can’t add line breaks in my alert box. My code looks as follows I’m getting the error: Undeterminnated string literal If I remove the n from the string it works 100% b…
Splitting a Paragraph into 160 Character Pieces for Text Messaging
I’m having trouble with the logic of taking a paragraph of text and splitting it on words/sentences to send out in multiple text messages. Each text message can only have up to 160 characters. I want to cleanly break a paragraph up. Here is the solution (thanks Leventix!): Answer You can use wordwrap, t…
PHP RegExp for nested Div tags
I need a regexp I can use with PHP’s preg_match_all() to match out content inside div-tags. The divs look like this: I’ve come up with this regexp so far which matches out all divs with id=”t[number]” The problem is when the content consists of more divs, nested divs like this: Any ide…
Best way to do multiple constructors in PHP
You can’t put two __construct functions with unique argument signatures in a PHP class. I’d like to do this: What is the best way to do this in PHP? Answer I’d probably do something like this: Then if i want a Student where i know the ID: Or if i have an array of the db row: Technically you&…
Explode string only once on first occurring substring
preg_match() gives one match. preg_match_all() returns all matches. preg_split() returns all splits. How can I split only on the first match? Example: This is what I want: Answer Simply set $limit to 2 for 2 parts of the array. Thanks to @BenJames for mentioning: I tested and it works fine. The limit argument…
Parse string containing range of values to min and max variables
I’m looking for a nice way to parse a string into two variables using PHP. The variables are called minage and maxage, and they should be parsed according to the examples below: Answer Try this:
What http status code is supposed to be used to tell the client the session has timed out?
In a webpage, it uses YUI connection manager/datasource to send AJAX requests to the server, if the session (which contains the info on whether the user has been authenticated) has already timed out, those ajax responses that can only be viewed by authenticated users should return an http status code, telling…
Accessing @attribute from SimpleXML
I am having a problem accessing the @attribute section of my SimpleXML object. When I var_dump the entire object, I get the correct output, and when I var_dump the rest of the object (the nested tags), I get the correct output, but when I follow the docs and var_dump $xml->OFFICE->{‘@attributes…
Is object-oriented PHP slow?
I used to use procedural-style PHP. Later, I used to create some classes. Later, I learned Zend Framework and started to program in OOP style. Now my programs are based on my own framework (with …