php-general Digest 7 Feb 2010 01:41:54 -0000 Issue 6577

Topics (messages 301843 through 301855):

Help with regex (search/replace) please
        301843 by: Ryan S
        301844 by: Phpster
        301845 by: Ashley Sheridan
        301846 by: Ryan S
        301847 by: Ryan S
        301848 by: Ashley Sheridan
        301852 by: Al
        301854 by: Ryan S

Warning?
        301849 by: tedd
        301853 by: Jochem Maas

simplexml - can it do what I need?
        301850 by: TerryA
        301851 by: Shawn McKenzie

Re: PHP User
        301855 by: T L

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Hey guys,

As many of you might know, i totally suck at regex..so would really appreciate 
some help here.

Basically i have a html page with a lot of textboxes,radios,checkboxes etc 
i need your help in the form of a regex so that when i give it the name and 
value it gives me the entire code of that checkbox.
for example here are 2 checkboxes:

<input type="checkbox" name="something" value="1" />

<input type="checkbox" name="something2" value="2" id="something" 
onClick="javascript_code_etc()" onSomething="lots of js cod here()" />



so if i want the second checkbox code i was thinking of something like this:

$the_name="something2";
$the_value="2";
$fetched=getCheckboxFromHTML($the_name,$the_value);

and then if successful the variable $fetched would contain
<input type="checkbox" name="something2" value="2" id="something" 
onClick="javascript_code_etc()" onSomething="lots of js cod here()" />

the idea is that i would use the contents of $fetch to add some code before the 
end just before  the greater than symbol, and do a str_replace().

What do you think? Critique of my logic above too is welcome!

Thanks!
Ryan


      

--- End Message ---
--- Begin Message ---
Why not just pass the value in the onclick?

Onclick=doSomething(this);

Would give you simple access to all the properties of that element.

This.value would pass just the value.



Bastien

Sent from my iPod

On Feb 6, 2010, at 9:43 AM, Ryan S <gen...@yahoo.com> wrote:

Hey guys,

As many of you might know, i totally suck at regex..so would really appreciate some help here.

Basically i have a html page with a lot of textboxes,radios,checkboxes etc i need your help in the form of a regex so that when i give it the name and value it gives me the entire code of that checkbox.
for example here are 2 checkboxes:

<input type="checkbox" name="something" value="1" />

<input type="checkbox" name="something2" value="2" id="something" onClick="javascript_code_etc()" onSomething="lots of js cod here()" />



so if i want the second checkbox code i was thinking of something like this:

$the_name="something2";
$the_value="2";
$fetched=getCheckboxFromHTML($the_name,$the_value);

and then if successful the variable $fetched would contain
<input type="checkbox" name="something2" value="2" id="something" onClick="javascript_code_etc()" onSomething="lots of js cod here()" />

the idea is that i would use the contents of $fetch to add some code before the end just before the greater than symbol, and do a str_replace().

What do you think? Critique of my logic above too is welcome!

Thanks!
Ryan




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
On Sat, 2010-02-06 at 06:43 -0800, Ryan S wrote:

> Hey guys,
> 
> As many of you might know, i totally suck at regex..so would really 
> appreciate some help here.
> 
> Basically i have a html page with a lot of textboxes,radios,checkboxes etc 
> i need your help in the form of a regex so that when i give it the name and 
> value it gives me the entire code of that checkbox.
> for example here are 2 checkboxes:
> 
> <input type="checkbox" name="something" value="1" />
> 
> <input type="checkbox" name="something2" value="2" id="something" 
> onClick="javascript_code_etc()" onSomething="lots of js cod here()" />
> 
> 
> 
> so if i want the second checkbox code i was thinking of something like this:
> 
> $the_name="something2";
> $the_value="2";
> $fetched=getCheckboxFromHTML($the_name,$the_value);
> 
> and then if successful the variable $fetched would contain
> <input type="checkbox" name="something2" value="2" id="something" 
> onClick="javascript_code_etc()" onSomething="lots of js cod here()" />
> 
> the idea is that i would use the contents of $fetch to add some code before 
> the end just before  the greater than symbol, and do a str_replace().
> 
> What do you think? Critique of my logic above too is welcome!
> 
> Thanks!
> Ryan
> 
> 
>       
> 


Rather than a regex, you're probably better off using something like
DomDocument, where you can iterate over all of the input elements in the
document, and check the attributes of each one to check if they match
your criteria.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Hey guys,

As many of you might know, i totally suck at regex..so would really appreciate 
some help here.

Basically i have a html page with a lot of textboxes,radios,checkboxes etc 
i need your help in the form of a regex so that when i give it the name and 
value it gives me the entire code of that checkbox.
for example here are 2 checkboxes:

<input type="checkbox" name="something" value="1" />

<input
type="checkbox" name="something2" value="2" id="something"
onClick="javascript_code_etc()" onSomething="lots of js cod here()"
/>



so if i want the second checkbox code i was thinking of something like this:

$the_name="something2";
$the_value="2";
$fetched=getCheckboxFromHTML($the_name,$the_value);

and then if successful the variable $fetched would contain
<input
type="checkbox" name="something2" value="2" id="something"
onClick="javascript_code_etc()" onSomething="lots of js cod here()"
/>

the idea is that i would use the contents of $fetch to add
some code before the end just before  the greater than symbol, and do a
str_replace().

What do you think? Critique of my logic above too is welcome!

Thanks!
Ryan



      

--- End Message ---
--- Begin Message ---
Hey Ash,Bastien!
<clip>

Rather than a regex, you're probably better off using something like 
DomDocument, where you can iterate over all of the input elements in the 
document, and check the attributes of each one to check if they match your 
criteria.
</clip>

@Ash, You're kinda reading my mind... i did do this in domDocument but it didnt 
work out so well... so now am trying to do this in a diff way.
Is it ok if i send you the code via an attachment? it is REALLLL messy code 
right now though.

@Bastien, you're talking client side... i need to do this server side as then i 
am writing the results to a file which is going to be used as a template in 
other scripts.

Thanks!
Ryan


      

--- End Message ---
--- Begin Message ---
On Sat, 2010-02-06 at 07:53 -0800, Ryan S wrote:

> Hey Ash,Bastien!
> <clip>
> 
> Rather than a regex, you're probably better off using something like 
> DomDocument, where you can iterate over all of the input elements in the 
> document, and check the attributes of each one to check if they match your 
> criteria.
> </clip>
> 
> @Ash, You're kinda reading my mind... i did do this in domDocument but it 
> didnt work out so well... so now am trying to do this in a diff way.
> Is it ok if i send you the code via an attachment? it is REALLLL messy code 
> right now though.
> 
> @Bastien, you're talking client side... i need to do this server side as then 
> i am writing the results to a file which is going to be used as a template in 
> other scripts.
> 
> Thanks!
> Ryan
> 
> 
>       


I'm not going to be about for most of the weekend now, so it might be
better putting the code in something like pastebin and posting a link to
it on here!

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
have you looked at the Pear html_QuickForm2 set?

On 2/6/2010 9:43 AM, Ryan S wrote:
Hey guys,

As many of you might know, i totally suck at regex..so would really appreciate 
some help here.

Basically i have a html page with a lot of textboxes,radios,checkboxes etc
i need your help in the form of a regex so that when i give it the name and 
value it gives me the entire code of that checkbox.
for example here are 2 checkboxes:

<input type="checkbox" name="something" value="1" />

<input type="checkbox" name="something2" value="2" id="something" 
onClick="javascript_code_etc()" onSomething="lots of js cod here()" />



so if i want the second checkbox code i was thinking of something like this:

$the_name="something2";
$the_value="2";
$fetched=getCheckboxFromHTML($the_name,$the_value);

and then if successful the variable $fetched would contain
<input type="checkbox" name="something2" value="2" id="something" 
onClick="javascript_code_etc()" onSomething="lots of js cod here()" />

the idea is that i would use the contents of $fetch to add some code before the 
end just before  the greater than symbol, and do a str_replace().

What do you think? Critique of my logic above too is welcome!

Thanks!
Ryan




--- End Message ---
--- Begin Message ---
@Al,


> have you looked at the Pear html_QuickForm2 set?

Actually nope, whats it about? just did a google search and found it on the php 
site but no example code around so dont really have a clue.

@Ash,
Pastebin! Of course, why didnt i think of that... will do!

Actually, just did so that i wouldht have to double post to the list.

heres the pastebin url
http://pastebin.com/m18b6fb86

I cleaned up a lot of surrounding code so its a bit more readable leaving only 
the relevant code.

Theres one thing quite strange that i have to mention, this code:

if($input->getAttribute("type") ==strtolower("radio") && 
$input->getAttribute("name") ==strtolower("living_in_prague"))

works find
but if I instead use

if($input->getAttribute("type") ==strtolower("radio") && 
$input->getAttribute("name") ==strtolower("living_in_prague")  && 
$input->getAttribute("value") ==strtolower("0"))


OR


if($input->getAttribute("type") ==strtolower("radio") &&
$input->getAttribute("name") ==strtolower("living_in_prague")
&& $input->getAttribute("value") ==strtolower("0"))


OR


if($input->getAttribute("type") ==strtolower("radio") &&
$input->getAttribute("name") ==strtolower("living_in_prague")
&& $input->getAttribute("value") ==0))


It does not work... even though i KNOW that thats the correct value because i 
checked the static html page like 10 times...


      

--- End Message ---
--- Begin Message ---
Hi:

Has anyone encountered this warning?

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0

I seem to remember this happening before, but I don't remember the solution. As I remember, it wasn't really reporting an error, but something else. I just don't remember how I dealt with it before.

I don't know how to set session.bug_compat_warn to off.

Any ideas?

Cheers,

tedd

PS: I'm using php 5.2.10 and register_global is OFF.
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Op 2/6/10 4:29 PM, tedd schreef:
> Hi:
> 
> Has anyone encountered this warning?
> 
> Warning: Unknown: Your script possibly relies on a session side-effect
> which existed until PHP 4.2.3. Please be advised that the session
> extension does not consider global variables as a source of data, unless
> register_globals is enabled. You can disable this functionality and this
> warning by setting session.bug_compat_42 or session.bug_compat_warn to
> off, respectively in Unknown on line 0
> 
> I seem to remember this happening before, but I don't remember the
> solution. As I remember, it wasn't really reporting an error, but
> something else. I just don't remember how I dealt with it before.
> 
> I don't know how to set session.bug_compat_warn to off.

doesn't this work?:

        <?php ini_set('session.bug_compat_warn', 0); ?>

otherwise you'll have to set it in php.ini (or a .htaccess file)

IIRC it means your using session_register() .. which is depreciated and
will be dropped in 5.3 ... AFAIK best practices is not to use this function
but instead assing to the $_SESSION superglobal.

e.g.

do:

<?php $_SESSION['foo'] = $foo; // assumes session_start() has already been 
called

instead of

<?php session_register('foo', $foo); // automatically calls session_start() if 
not already started.

> 
> Any ideas?
> 
> Cheers,
> 
> tedd
> 
> PS: I'm using php 5.2.10 and register_global is OFF.


--- End Message ---
--- Begin Message ---
My first post and I'm just a few days into learning PHP so that I can extract
data from an XML feed for updating a MySQL driven website. Simplexml grabs
most of my data without a problem but I can't get at the data in elements
such as: 
<element idtype="11" lang="fr" label="Description - Etage"><![CDATA[Rez de
jardin]]></element>
<element idtype="1" lang="fr" label="Description - Nombre de
pièces"><![CDATA[1]]></element>
<element idtype="2" lang="fr" label="Description - Nombre de
chambres"><![CDATA[0]]></element>
<element idtype="3" lang="fr" label="Description - Surface totale
(m²)"><![CDATA[27]]></element>
I have around a hundred of these elements but only need data from two of
them. I need to extract the CDATA by specifying the idtype and lang
attribute. For example, in the first of these elements, I need to be able to
get out the string "Rez de jardin" by specifying idtype="11" and lang="fr".
Can I use Simplexml to do this and, if so, how? If not, what should I use?
Many thanks for any help.
Terry
-- 
View this message in context: 
http://old.nabble.com/simplexml---can-it-do-what-I-need--tp27481222p27481222.html
Sent from the PHP - General mailing list archive at Nabble.com.


--- End Message ---
--- Begin Message ---
TerryA wrote:
> My first post and I'm just a few days into learning PHP so that I can extract
> data from an XML feed for updating a MySQL driven website. Simplexml grabs
> most of my data without a problem but I can't get at the data in elements
> such as: 
> <element idtype="11" lang="fr" label="Description - Etage"><![CDATA[Rez de
> jardin]]></element>
> <element idtype="1" lang="fr" label="Description - Nombre de
> pièces"><![CDATA[1]]></element>
> <element idtype="2" lang="fr" label="Description - Nombre de
> chambres"><![CDATA[0]]></element>
> <element idtype="3" lang="fr" label="Description - Surface totale
> (m²)"><![CDATA[27]]></element>
> I have around a hundred of these elements but only need data from two of
> them. I need to extract the CDATA by specifying the idtype and lang
> attribute. For example, in the first of these elements, I need to be able to
> get out the string "Rez de jardin" by specifying idtype="11" and lang="fr".
> Can I use Simplexml to do this and, if so, how? If not, what should I use?
> Many thanks for any help.
> Terry

Look at the options:

$xml = simplexml_load_file('file.xml', 'SimpleXMLElement', LIBXML_NOCDATA);

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
Hello,

Depends on what you're looking to do.

For intermediate PHP I like

PHP Object-Oriented Solutions by David Powers (friends of ED)

The focus is on PHP 5...not sure if anyone outside of shared hosting uses
PHP 4, but worth a mention.

Regarding PHP In Action,
This might just be me personally, but I found PHP In Action to be a somewhat
difficult read--the authors really focus on nuance and try to show a "shades
of gray".  This means discussions on how PHP is different than Java, how PHP
5 is different than PHP 4, how this solution is subtly different than that
one, etc.  If you are new to ideas on both sides of the comparison, the
multitudes of comparisons can become a little tedious.

Basically, I would NOT recommend this book if you are trying to get a
refresher on syntax or are an amature/part-time programmer.  However, it
does have quite a few worthwhile sections--the authors are obviously
familiar with software design and the book is literally littered with
references to Folwer, GOF, TDD, Beck, etc--that try to bring in best
practices (largely from Java) to PHP (5).

Apologies for the rambling, both books are on amazon with a number of
reviews.

Cheers,
Tim





On Thu, Feb 4, 2010 at 12:17 AM, Paul M Foster <pa...@quillandmouse.com>wrote:

> On Thu, Feb 04, 2010 at 03:13:00PM +1030, abby ragz wrote:
>
> >
> > Hi,
> >
> > I used PHP 3 years back and was a standard user.
> >
> > but now I want to update myself and do self - study .
> >
> >
> >
> > Please advise from where should I start.
> >
> > Any good site recommendations.
>
> Programming PHP by Lerdorf, Tatroe, MacIntyre (O'Reilly)
>
> http://php.net/manual/en/
>
> For object oriented PHP code,
>
> PHP In Action: Objects, Design, Agility by Reiersol, Baker, Shiflett
> (Manning)
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Tim Loudon
(781) 686-6096

--- End Message ---

Reply via email to