To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > General Help

General Help Forum for General Help questions pertaining to PHP

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-25-2003, 05:09 PM   #1
JCScoobyRS
Member
 
Join Date: Jan 2003
Location: Somewhere in CO
Posts: 54
Handling the Double Quote

I am trying to use highlight_string to display PHP code and if the code has any double quotes in it, it gets marked up all wrong. Is there anyway to work around this? Thanks, Jeremy
__________________
He who listens well, speaks well.

DeveloperKB
JCScoobyRS is offline   Reply With Quote
Old 06-25-2003, 06:38 PM   #2
ereptur
PHP Enthusiast
 
ereptur's Avatar
 
Join Date: Jan 2003
Location: Des Moines, IA
Posts: 351
try an addslashes before you use highlight_string.
__________________
http://www.burnt-popcorn.com
Learning to code is just that, a LEARNING experience. It is necessary to LOOK for the information you seek on your road to becoming a Guru.
ereptur is offline   Reply With Quote
Old 06-25-2003, 06:56 PM   #3
JCScoobyRS
Member
 
Join Date: Jan 2003
Location: Somewhere in CO
Posts: 54
Here is what I did to get past the double quote:

PHP Code:
function highlight_code ($langName, $codeText)
    {
        $langName = strtolower($langName);
        require_once XOOPS_ROOT_PATH."/colorcode/HColor_Core.php";
        if ($langName == 'php'){
            $codeText = str_replace('\\','\\\\',$codeText);
            $codeText = highlight_string("<?$codeText?".">", TRUE);
            $codeText = str_replace('
\\\\','\\',$codeText);
            return $codeText;
        
}else{
            $HColor = new HColorCore;
            $codeText = $HColor
->HighlightColor($langName,$codeText);
            return $codeText;
        
}
    
}
Now, I'm getting this as the output when $codeText = the function:

PHP Code:
function highlight_code ($langName, $codeText)
    {
        $langName = strtolower($langName);
        require_once XOOPS_ROOT_PATH."/colorcode/HColor_Core.php";
        if ($langName == 'php'){
            $codeText = str_replace('\','\\',$codeText);
            $codeText = highlight_string("<?$codeText?".">", TRUE);
            $codeText = str_replace('
\\','\',$codeText);
            return $codeText;
        
}else{
            $HColor = new HColorCore;
            $codeText = $HColor
->HighlightColor($langName,$codeText);
            return $codeText;
        
}
    
}
On the output...you'll notice that the "\\" became "\" and "\\\\" became "\\". Do you know why this is happening? Thanks, Jeremy
__________________
He who listens well, speaks well.

DeveloperKB
JCScoobyRS is offline   Reply With Quote
Old 06-25-2003, 07:41 PM   #4
HalfaBee
Not very lazy.
 
Join Date: Jun 2003
Location: Sydney, Australia
Posts: 1,851
I tried it and found this string worked fine $codetext = '\'\n\r\'';

You have to use the addslashes function to escape the quotes and then it should work.

HalfaBee
HalfaBee is offline   Reply With Quote
Old 06-25-2003, 07:45 PM   #5
JCScoobyRS
Member
 
Join Date: Jan 2003
Location: Somewhere in CO
Posts: 54
I'm still new...could you explain a bit more? Thanks alot, Jeremy
__________________
He who listens well, speaks well.

DeveloperKB
JCScoobyRS is offline   Reply With Quote
Old 06-25-2003, 07:50 PM   #6
HalfaBee
Not very lazy.
 
Join Date: Jun 2003
Location: Sydney, Australia
Posts: 1,851
You need to add

$codeText = addslashes( $codeText );

before the highlight_string()
and remove the str_replace()'s

Halfabee
HalfaBee is offline   Reply With Quote
Old 06-26-2003, 11:28 AM   #7
JCScoobyRS
Member
 
Join Date: Jan 2003
Location: Somewhere in CO
Posts: 54
I tried that and I'm back to square one. In square one...the markup for the PHP code was all wrong. It had over half of the code that I wanted marked up as a text string (red). Here is the code I'm trying to mark up:

Code:
function highlight_code ($langName, $codeText)
    {
        $langName = strtolower($langName);
    	require_once XOOPS_ROOT_PATH."/colorcode/HColor_Core.php";
    	if ($langName == 'php'){
    	    $codeText = str_replace('\\','\\\\',$codeText);
    	    $codeText = highlight_string("<?$codeText?".">", TRUE);
    	    //$codeText = str_replace('\\\\','\\',$codeText);
    	    return str_replace('\"','"',$codeText);
    	}else{
    	    $HColor = new HColorCore;
    	    $codeText = $HColor->HighlightColor($langName,$codeText);
    	    return $codeText;
    	}
    }
This also happens to be the function right now as is. It works for nearly ALL PHP code. When I mark it up the way you suggested, from the end the end of line 4 (require once), all code from "; on that line is red. The way the funtion is now...it marksup properly but it will take the "\\" and turn it into "\" and it will take "\\\\" and turn it into "\\". This isn't a big problem and I could probably deal without fixing it BUT there has to be a way to use highlight_string to beautify ANY PHP code. Right now...I'm having to jump through hoops to do it and the way posted, works if you don't have "\\" or "\\\\". Got anymore ideas? Thanks, Jeremy
__________________
He who listens well, speaks well.

DeveloperKB
JCScoobyRS is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 12:58 PM.






Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.