/    Sign up×
Community /Pin to ProfileBookmark

ok, i’m trying to get the exact same code that parses this and other sites’ [ php][/ php] tags, it’s proving difficult though

basically what i want to do is have

[code=php]

if ($cow == “beef”) $bovine = “meat”;
else $bovine = “milk”;

[/code]

working on my script.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 12.2010 — Not sure I understand the question, but perhaps at least part of the answer is [url=http://php.net/highlight_string]highlight_string[/url]()?
Copy linkTweet thisAlerts:
@phoenixbytesauthorMar 12.2010 — i have a mobile web forum, on it i have bbcode

users do [b] [ /b] they get bold etc



i'm trying to do the one for
[code=php][ /php]
Copy linkTweet thisAlerts:
@MindzaiMar 12.2010 — So which part is giving you issues? As NogDog has mentioned, highlight_string() will give you the syntax highlighting (as will GeSHi if you want something more advanced).
Copy linkTweet thisAlerts:
@phoenixbytesauthorMar 12.2010 — i'm using

[code=php]function bbcode($s)
{
$s = str_replace("]n", "]", $s);
$match = array('#[php](.*?)[/php]#se');
$replace = array("'<div>'.highlight_string(stripslashes('$1'), true).'</div>'");
return preg_replace($match, $replace, $s);
}
[/code]


but the output it's giving me is identical to: if ($cow == "beef") $bovine = "meat"; <br/>else $bovine = "milk";


notice the <br/> tag in the output?

it's killing off carriage returns
Copy linkTweet thisAlerts:
@MindzaiMar 12.2010 — There's nothing in the code you posted which is converting newline and/or carriage return characters into <br /> tags. You need to locate whatever code is doing that (a nl2br() call somewhere?) and stop it. You [I]could[/I] replace the <br /> tags of course, but that's problematic if the php code contains such a tag itself, which is why I suggest tracking down the source of the <br />.
×

Success!

Help @phoenixbytes spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...