My string of text looks like this: I need to get just the part before the @ and nothing else. The text is coming from a simple XML object if that matters any. The code I have looks like this: Sometimes the username might have numbers or an underscore before the @ symbol, which is where the regex stops it
jQuery Ajax on Different Port
My php file located at port 80 (default port) while my ajax call are on port 8080. My index.html on port 8080 $(document).ready(function(){ $.get(“userCheck.php”, {“username” : “lazy”, “…
How do I PHP-unserialize a jQuery-serialized form?
Using $(‘#form’).serialize(), I was able to send this over to a PHP page. Now how do I unserialize it in PHP? It was serialized in jQuery. Answer You shouldn’t have to unserialize anything in PHP from the jquery serialize method. If you serialize the data, it should be sent to PHP as query p…
Passing arrays as url parameter
What is the best way that I can pass an array as a url parameter? I was thinking if this is possible: or how about this: Ive read examples, but I find it messy: Answer There is a very simple solution: http_build_query(). It takes your query parameters as an associative array: will return http_build_query() ha…
PHP gdLib 8-Bit PNG with alpha
how is it possible to save my image, created with gd, as an png-8? it saves as gif with transparent channel well – but I want to use png-8. Best Regards, Beerweasle Answer Using imagesavealpha() and a transparent bg color should do the trick… Based on dfilkovi’s code:
curl error 18 – transfer closed with outstanding read data remaining
when retrieving data from a URL using curl, I sometimes (in 80% of the cases) get error 18: transfer closed with outstanding read data remaining Part of the returned data is then missing. The weird thing is that this does never occur when the CURLOPT_RETURNTRANSFER is set to false, that is the curl_exec funct…
401 error on iis when uploading files via PHP
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
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…