php-general Digest 18 Aug 2008 07:25:40 -0000 Issue 5630
Topics (messages 278250 through 278264):
undefine variable
278250 by: Michael S. Dunsavage
278251 by: Ashley Sheridan
278258 by: Michael S. Dunsavage
Breaking a line in two
278252 by: Ron Piggott
278253 by: Ashley Sheridan
278254 by: Lupus Michaelis
278255 by: Warren Vail
Negative Look Ahead Regex - Code Mistake or Bug?
278256 by: Cameron B. Prince
278257 by: Ashley Sheridan
278259 by: Cameron B. Prince
278261 by: Simcha Younger
278263 by: Lupus Michaelis
278264 by: Lupus Michaelis
Re: FCKEditor, TinyMCE, ... I need a light weight WYSIWYG HTML Editor
278260 by: Warren Vail
Regarding threads...
278262 by: Nagalakshmi Parameswaran
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
I'm having a problem running a form script. It used to work before, but
now when I submit the form an error pops up and it won't write to the
database:
This is the error:
[Sun Aug 17 16:46:54 2008] [error] [client 127.0.0.2] PHP Notice:
Undefined variable: selected_state
in /srv/www/htdocs/djtommer/contact.php on line
243
This is the code:
-------------
foreach($state_list as $key=>$value){
if($selected_state == $key){
$sel = 'selected="selected"';
}
else{
$sel = '';
}
echo "<option $sel value=\"$key\">$value</option>";
}
echo '</select>';
?>
----------
--
Michael S. Dunsavage
--- End Message ---
--- Begin Message ---
Hi Michael,
It seems that you are trying to use the $selected_state variable in the
code, but it hasn't been declared yet. To test if a variable exists, you
can use the isset() function.
Also, there is a quick way of writing your if/else check on one line.
Here's the changes:
foreach($state_list as $key=>$value)
{
$sel = (isset($selected_state) && $selected_state ==
$key)?'selected="selected"':'';
echo "<option $sel value=\"$key\">$value</option>";
}
echo '</select>';
?>
(That's only two lines there inside the loop, just incase my email
client breaks the line because of wordwrap.)
Obviously, if your code worked before, but now is not, it might be that
some other change in your code is causing this error, and that
introducing my change will only mask a larger logic error. You should go
through your code to check where the $selected_state variable is meant
to be declared to make sure it really is.
There is another explanation. If you are not in control of your hosting,
it could be that they changed the error reporting level to show notices
as well, which I believe aren't turned on by default on all hosting
packages.
Ash
www.ashleysheridan.co.uk
--- Begin Message ---
I'm having a problem running a form script. It used to work before, but
now when I submit the form an error pops up and it won't write to the
database:
This is the error:
[Sun Aug 17 16:46:54 2008] [error] [client 127.0.0.2] PHP Notice:
Undefined variable: selected_state
in /srv/www/htdocs/djtommer/contact.php on line
243
This is the code:
-------------
foreach($state_list as $key=>$value){
if($selected_state == $key){
$sel = 'selected="selected"';
}
else{
$sel = '';
}
echo "<option $sel value=\"$key\">$value</option>";
}
echo '</select>';
?>
----------
--
Michael S. Dunsavage
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- End Message ---
--- Begin Message ---
On Sun, 2008-08-17 at 22:26 +0100, Ashley Sheridan wrote:
> Hi Michael,
>
> It seems that you are trying to use the $selected_state variable in the
> code, but it hasn't been declared yet. To test if a variable exists, you
> can use the isset() function.
>
> Also, there is a quick way of writing your if/else check on one line.
> Here's the changes:
>
> foreach($state_list as $key=>$value)
> {
> $sel = (isset($selected_state) && $selected_state ==
> $key)?'selected="selected"':'';
> echo "<option $sel value=\"$key\">$value</option>";
> }
> echo '</select>';
> ?>
>
> (That's only two lines there inside the loop, just incase my email
> client breaks the line because of wordwrap.)
>
> Obviously, if your code worked before, but now is not, it might be that
> some other change in your code is causing this error, and that
> introducing my change will only mask a larger logic error. You should go
> through your code to check where the $selected_state variable is meant
> to be declared to make sure it really is.
>
> There is another explanation. If you are not in control of your hosting,
> it could be that they changed the error reporting level to show notices
> as well, which I believe aren't turned on by default on all hosting
> packages.
Heh, actually that wasn't the problem after all. Well php still yells @
me about it, but it does work. In fact someone on this list helped me
before, sorry if I can't remember your name who it was :). But it
wasn't writing to the DB and I discovered I had to change the
permissions (it was a backup I had restored) and restart mysql. But you
have a lot of useful information in your list, so I'll be keeping it.
--
Michael S. Dunsavage
--- End Message ---
--- Begin Message ---
Is there a way to add
<br>
midway through a string, following the first available space?
Example:
The cat jumped up high.
This is 23 characters long. I want <br> added after the 12th character,
following the first space:
The cat jumped <br>up high.
would be the desired output.
Ron
--- End Message ---
--- Begin Message ---
Hi Ron,
This should do the trick:
<?php
$string = "The cat jumped up high.";
$pos = strpos($string, ' ', strlen($string)/2) + 1;
$new_string = substr_replace($string, '<br/>', $pos, 0);
?>
Ash
www.ashleysheridan.co.uk
--- Begin Message ---
Is there a way to add
<br>
midway through a string, following the first available space?
Example:
The cat jumped up high.
This is 23 characters long. I want <br> added after the 12th character,
following the first space:
The cat jumped <br>up high.
would be the desired output.
Ron
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- End Message ---
--- Begin Message ---
Ron Piggott a écrit :
This is 23 characters long. I want <br> added after the 12th character,
following the first space:
I guess you want to use wordwrap <http://www.php.net/wordwrap> and
nl2br <http://www.php.net/nl2br>.
--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org
--- End Message ---
--- Begin Message ---
You might want to consider wordwrap(), which will count out to the length
you specify.
If the next character is not a blank, it will back up to the first available
blank and insert the break character you choose at that point (inplace of
the blank), "<br>" is a valid option, and it will continue doing this until
the line is broken up into as many lines as it takes that are never longer
than the number specified. If you want to divide it in half divide strlen()
by two.
Wordwrap would work like you specify, if you use 15 as the max length,
except that it would not leave the blank at the end of the line (can't
imagine why you'd want that). Also since you goal is to limit the size of a
line, not sure why you'd want have it add to the length looking for the
blank, suppose the word at character position 10 (in your case) was
"supercallifragilisticexprealidoceous", do you really want your line to be
46 characters long because a long word was placed at the break point?
Hth,
Warren Vail
> -----Original Message-----
> From: Ron Piggott [mailto:[EMAIL PROTECTED]
> Sent: Sunday, August 17, 2008 3:11 PM
> To: PHP General
> Subject: [PHP] Breaking a line in two
>
>
> Is there a way to add
>
> <br>
>
> midway through a string, following the first available space?
>
> Example:
>
> The cat jumped up high.
>
> This is 23 characters long. I want <br> added after the 12th
> character, following the first space:
>
> The cat jumped <br>up high.
>
> would be the desired output.
>
> Ron
>
>
>
> --
> PHP General Mailing List (http://www.php.net/) To
> unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Hello,
I¹ve run into a problem with a regex and need help determining if this is my
mistake or a bug. The regex is for inserting a SID into every link in the
buffer before it¹s flushed, but only when each link doesn¹t already have a
SID.
An example of the code is here:
$buffer =
preg_replace('/"http\:\/\/www\.domain\.com([\/\w\.-]*)(?!\?PHPSESSID\=2u0cca
ffoh6jaeapkke35qpp87;?)/',
'"http://www.domain.com$1?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;', $buffer);
The code works correctly in most cases except when a SID already exists and
there is a path after the .com such as:
http://www.domain.com/path1/path2.php?PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
When this URL is processed by the regex, it becomes:
http://www.domain.com/path1/path2.ph?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;p?
PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
So the problem is the regex not only falsely matches, it's inserting the SID
in between 2nd and 3rd letters of the extension.
You can see the code in action here:
http://kottmann.com/test.php
The full source for the test code is also available when viewing the source
of this page.
I've tested this on PHP v5.1.6 and PHP v5.2.6.
TIA,
Cameron
--- End Message ---
--- Begin Message ---
Hi Cameron,
As far as I can tell, you have an error in your syntax. You're using a -
(hyphen) character in the first match, but Regex uses this to define a
range of characters. It seems that if you don't escape it, the whole
thing behaves a little strangely. For example, using your URL as the
source string:
http://www.domain.com/path1/path2.php?PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
This regular expression
/^(http:\/\/www\.domain\.com([\/\.\-\_\w]*))/
matches
[!MATCH!]?PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
and this
/^(http:\/\/www\.domain\.com([\/\.-\_\w]*))/
matches the whole URL
The only difference is the hyphen has been escaped in the first
expression.
I'm not sure if this will help any, but it's definitely something I
noticed in the regex.
Ash
www.ashleysheridan.co.uk
--- Begin Message ---
Hello,
I¹ve run into a problem with a regex and need help determining if this is my
mistake or a bug. The regex is for inserting a SID into every link in the
buffer before it¹s flushed, but only when each link doesn¹t already have a
SID.
An example of the code is here:
$buffer =
preg_replace('/"http\:\/\/www\.domain\.com([\/\w\.-]*)(?!\?PHPSESSID\=2u0cca
ffoh6jaeapkke35qpp87;?)/',
'"http://www.domain.com$1?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;', $buffer);
The code works correctly in most cases except when a SID already exists and
there is a path after the .com such as:
http://www.domain.com/path1/path2.php?PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
When this URL is processed by the regex, it becomes:
http://www.domain.com/path1/path2.ph?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;p?
PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
So the problem is the regex not only falsely matches, it's inserting the SID
in between 2nd and 3rd letters of the extension.
You can see the code in action here:
http://kottmann.com/test.php
The full source for the test code is also available when viewing the source
of this page.
I've tested this on PHP v5.1.6 and PHP v5.2.6.
TIA,
Cameron
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- End Message ---
--- Begin Message ---
Hi Ash,
> As far as I can tell, you have an error in your syntax. You're using a -
> (hyphen) character in the first match, but Regex uses this to define a
> range of characters. It seems that if you don't escape it, the whole
> thing behaves a little strangely. For example, using your URL as the
> source string:
>
> http://www.domain.com/path1/path2.php?PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
>
> This regular expression
> /^(http:\/\/www\.domain\.com([\/\.\-\_\w]*))/
> matches
> [!MATCH!]?PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
Thanks for your reply. I updated the code at the URL below adding your
suggestion, but it doesn't seem to make a difference.
http://www.kottmann.com/test.php
Even if there is a problem with the meta characters, I don't understand how
or why the SID would be added in between the .ph and the p in the extension.
It's just totally bizarre to me and is why I'm wondering if it's a bug. (See
links 1 & 8 by viewing source at the link above)
You or anyone have other ideas to try?
Thanks,
Cameron
--- End Message ---
--- Begin Message ---
Hi
You did not put a question mark in your character class ([\/\w\.-] and
instead you put it together with the session id.
The expression looks for a sequence without which is not followed by the
next expression --- ?PHPSESSID\=2u0cca.....
If it would count the last `p` of `.php` then the next expression would
violate the negative lookahead.
Instead it stops just before it, after the `.ph` which is the longest
expression it could find that fulfills your negative lookahead, and then it
inserts the new sessionid over there.
Try instead
$buffer =
preg_replace('/"http\:\/\/www\.domain\.com([\/\w\.\-]*\??)(?!PHPSESSID\=2u0c
caffoh6jaeapkke35qpp87;?)/',
'"http://www.domain.com$1?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;', $buffer);
(not tested)
Simcha Younger
-----Original Message-----
From: Cameron B. Prince [mailto:[EMAIL PROTECTED]
Sent: Monday, August 18, 2008 12:56 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Negative Look Ahead Regex - Code Mistake or Bug?
Hello,
I¹ve run into a problem with a regex and need help determining if this is my
mistake or a bug. The regex is for inserting a SID into every link in the
buffer before it¹s flushed, but only when each link doesn¹t already have a
SID.
An example of the code is here:
$buffer =
preg_replace('/"http\:\/\/www\.domain\.com([\/\w\.-]*)(?!\?PHPSESSID\=2u0cca
ffoh6jaeapkke35qpp87;?)/',
'"http://www.domain.com$1?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;', $buffer);
The code works correctly in most cases except when a SID already exists and
there is a path after the .com such as:
http://www.domain.com/path1/path2.php?PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
When this URL is processed by the regex, it becomes:
http://www.domain.com/path1/path2.ph?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;p?
PHPSESSID=2u0ccaffoh6jaeapkke35qpp87;
So the problem is the regex not only falsely matches, it's inserting the SID
in between 2nd and 3rd letters of the extension.
You can see the code in action here:
http://kottmann.com/test.php
The full source for the test code is also available when viewing the source
of this page.
I've tested this on PHP v5.1.6 and PHP v5.2.6.
TIA,
Cameron
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.138 / Virus Database: 270.6.4/1617 - Release Date: 17/08/2008
12:58
--- End Message ---
--- Begin Message ---
Ashley Sheridan a écrit :
Hi Cameron,
As far as I can tell, you have an error in your syntax. You're using a -
(hyphen) character in the first match, but Regex uses this to define a
range of characters.
That's not valuable if hyphen is the last character of the range set.
--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org
--- End Message ---
--- Begin Message ---
Cameron B. Prince a écrit :
An example of the code is here:
$buffer =
preg_replace('/"http\:\/\/www\.domain\.com([\/\w\.-]*)(?!\?PHPSESSID\=2u0cca
ffoh6jaeapkke35qpp87;?)/',
'"http://www.domain.com$1?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;', $buffer);
I never build my regex inline. I write them by pieces I can test. It
is obviously to divide (and I don't know in english the end). So when
the starting and ending marks are too frequents in my pattern, I use an
other mark (like `).
$domain = '(http://www\.domain\.com)' ;
$path = '(/\\w*)+' ;
$search_part = 'PHPSESSID=(?:[\w\d]+)' ;
$re = sprintf("`%s%s?%s`", $domain, $path, $search_part) ;
$buffer = '\1\2?PHPSESSID=t9gksvpdcuobsnqt98qloe6lg4;' ;
$buffer = preg_match($re, $url, $buffer) ;
So said, it doesn't work anymore when you'll have other parameters in
your search part.
--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org
--- End Message ---
--- Begin Message ---
A textarea is a simple editor, I am assuming you want something better than
that, or you wouldn't have looked further.
Have you heard the expression (there is no free lunch), it applies here.
Strictly speaking, a textarea is a wysiwyg editor, (what you see is what you
get) you just don't see or get very much, one font, no formatting(other than
what you can do with a carriage return, or a space bar).
These editors can be very complex, but you do have some control in most of
them to manage the complexity that you reveal to your users, and to do that
you will have to know more about it than your users do (again, no free
lunch).
I like TinyMCE, it allows me to make sure that my users have a simple
interface, and is real easy to setup (relative to developing the whole thing
myself), but most of the ones you cite can probably fill that bill.
Warren Vail
> -----Original Message-----
> From: mike [mailto:[EMAIL PROTECTED]
> Sent: Sunday, August 17, 2008 12:05 PM
> To: AmirBehzad Eslami
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP] FCKEditor, TinyMCE, ... I need a light
> weight WYSIWYG HTML Editor
>
> On 8/17/08, AmirBehzad Eslami <[EMAIL PROTECTED]> wrote:
> > Dear list,
> >
> > I'm looking for a light weight WYSIWYG HTML Editor to allow
> users to
> > send private messages to each other in a forum application.
> >
> > FCKEditor is too complex and very huge for my purposes. I want a
> > simple editor. What do you recommend?
>
> WordPress has tweaked tinymce a lot to maintain <p> spacing
> and code snippets and embedded objects. We've tried both at
> my job with various configurations, both have had issues -
> but we've had the most success and our users have been happy
> with WordPress's configuration (which uses a couple custom
> javascript things + specific tinymce
> configuration)
>
> I've been trying to examine the differences so I can create a
> reusable standalone component we can use in all our various
> apps... but WP has hooked in a lot of custom code and it's
> been a bit annoying trying to split it out into a single
> reusable javascript file and stuff. Almost done though. I
> went overboard and tried to make it more generic by renaming
> and cleaning up the functions to not need any WordPress
> callbacks and stuff and wound up messing it up, so I have to
> go back again and probably re-create it from scratch.. Doh :)
>
> Honestly in a forum setting you can just give them a bbcode
> howto/link on the side and let them put in their own bbcode
> (which can be a strict subset of HTML) - or even just allow
> HTML tags and limit what they can do. Loading up a
> javascript-based thing even if it's pretty lightweight is
> still annoying and I could see that being overkill for a forum.
>
> --
> PHP General Mailing List (http://www.php.net/) To
> unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
Hello friends,
hope we all know about threads in java..........
Like that, can we use that in php?.......
Thanks in advance............
--- End Message ---