Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
testy1
Involved
Involved



Joined: Apr 06, 2008
Posts: 484

PostPosted: Tue Feb 17, 2009 6:12 pm Reply with quote

I assume I would use reg ex for this but anyway here we go Smile

if my var holds a javascript string (for adding custom code dynamically), how can i check the strings ends with a semi-colon.

example:
Code:



$myVar = 'this.insertBefore( elem, this.firstChild );';




it seems php has not yet built in the function

Code:


$myVar = Check_For_Stupid_SemiColon($myVar);



Shocked Laughing Laughing
 
View user's profile Send private message
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Tue Feb 17, 2009 8:34 pm Reply with quote

Code:


if (!preg_match("/;\z/", $myVar)) {
   $string = $myVar . ';';
}

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
Palbin







PostPosted: Tue Feb 17, 2009 8:35 pm Reply with quote

Awesome Tutorial!
[ Only registered users can see links on this board! Get registered or login! ]
 
testy1







PostPosted: Tue Feb 17, 2009 9:31 pm Reply with quote

ok thanks Smile
 
Palbin







PostPosted: Tue Feb 17, 2009 9:32 pm Reply with quote

The code I posted above was a little off.

Code:


if (!preg_match("/;\z/", $myVar)) {
   $myVar = $myVar . ';';
}
 
testy1







PostPosted: Wed Feb 18, 2009 5:21 am Reply with quote

I just had a thought Sad

I am getting these values from the database and they are inserted via a textarea.If they are entered on a per line basis it should be fine but if not it may cause issue's.

e.g.

Code:


this.insertBefore( elem, this.firstChild );
this.insertBefore( elem, this.firstChild );
this.insertBefore( elem, this.firstChild );
this.insertBefore( elem, this.firstChild );


Code:


this.insertBefore( elem, this.firstChild );this.insertBefore( elem, this.firstChild );this.insertBefore( elem, this.firstChild );this.insertBefore( elem, this.firstChild );


any ideas on that.
 
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Wed Feb 18, 2009 6:36 am Reply with quote

You almost need a javascript syntax checker (but I don't know of one off the top of my head). There are so many permutations that I am concerned about regex being able to cover them all. But, if there isn't such a thing out there, you may be stuck with writing maybe a series of regex's.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
testy1







PostPosted: Wed Feb 18, 2009 3:45 pm Reply with quote

or I could just enter them one per line ROTFL
 
montego







PostPosted: Wed Feb 18, 2009 8:57 pm Reply with quote

You just had to ask didn't you... killing me
 
testy1







PostPosted: Thu Feb 19, 2009 2:17 am Reply with quote

lol HitsFan
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©