הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   שאלה ב preg_replace (https://hosts.co.il/forums/showthread.php?t=20882)

-roee- 29-04-06 17:20

שאלה ב preg_replace
 
היי...

בניתי מן מערכת כזאת שאמורה להציג קודי PHP.. יעני אם רוצים שבתוך מקום מסויים יהיה קוד PHP צריך לכתוב בהתחלה: [mycode] ובסוף [/mycode]..
הרעיון הוא שהפונקציה highlight_string צובעת את שורות הקוד..

ובתוך הקובץ רשמתי משהו כזה:
PHP קוד:

$content preg_replace"#\[mycode\](.+?)\[/mycode\]#is""XXXXXXXXX"$content ); 

רק הבעיה היא שאין לי מושג מה לכתוב במקום XXXXXXXXX..

תודה רבה רבה

בניה 29-04-06 22:21

ב"ה

תנסה:
PHP קוד:

preg_match_all("#\[mycode\](.+?)\[/mycode\]#is",$content,$matchs,PREG_SET_ORDER);
for(
$i=0;$i<=count($matchs);$i++)
    {
    
$content=preg_replace("#\[mycode\](.+?)\[/mycode\]#is",highlight_string($matchs[$i][1]),$content,1);
    } 


-roee- 10-05-06 20:33

סבבה תודה על העזרה זה עובד לי אבל איך אפשר להפוך את התגים MYCODE ל DIV ככה שבו אני יוכל לקבוע את הSTYLE של ה קוד?

תודה

-roee- 11-05-06 17:51

בבקשה?

תודה

בניה 11-05-06 20:09

ב"ה


לא הבנתי.
אתה רוצה שבמקום שיכתבו [mycode] יכתבו div או שבמקום ה highlight_string יבואו divים ואיתם אתה תקבע את הגדרות הצבע?

miniature 11-05-06 20:10

ציטוט:

נכתב במקור על ידי בניה
ב"ה

שבמקום ה highlight_string יבואו divים ואיתם אתה תקבע את הגדרות הצבע

נראה לי שהוא התכוון לזה.

-roee- 11-05-06 20:43

אוקיי..
אני רוצה שאת התגים MYCODE הוא יהפוך ל DIV ואת מה שנמצא בינהם לעשות לו highligh_string

מובן?

תודה

בניה 11-05-06 21:20

ב"ה


תנסה:
PHP קוד:

<?php
preg_match_all
("#\[mycode\](.+?)\[/mycode\]#is",$content,$matchs,PREG_SET_ORDER);
for(
$i=0;$i<=count($matchs);$i++)
    {
    
$content=preg_replace("#\[mycode\](.+?)\[/mycode\]#is","<div>".highlight_string($matchs[$i][1])."</div>",$content,1);
    }
?>


-roee- 12-05-06 17:45

גבר, לא יודע למה אבל זה פשוט לא עובד לי..
הנה כל הקוד:

PHP קוד:

$id $_GET["id"];
$sql mysql_query("SELECT * FROM guildes WHERE id='$id'");

while(@(
$row=mysql_fetch_array($sql))) {
$id $row["id"];
$author $row["author"];
$name $row["name"];
$content $row["content"];

preg_match_all("#\[mycode\](.+?)\[/mycode\]#is",$content,$matchs,PREG_SET_ORDER); 
for(
$i=0;$i<=count($matchs);$i++) 
    { 
    
$content=preg_replace("#\[mycode\](.+?)\[/mycode\]#is","<div class=\"code\" style=\"margin:0px; padding:6px; border:1px inset; width:450px; overflow:auto\"><code style=\"white-space:nowrap\"><div dir=\"ltr\" style=\"text-align:left;\"><code><font color=\"#000000\">".highlight_string($matchs[$i][1])."</div></code></code></div>",$content,1); 
    } 

$description $row["description"];
$time $row["time"];
}



echo 
"
<div class=\"mydiv\">
<div class=\"title\">$name</div>
<div class=\"row\">
<a href=\"index.php\">דף הבית</a> -> <a href=\"index.php?act=guildes\">מדריכים</a> -> <b>$name</b>
<br><br>

<div align=\"center\">
  <center>
  <table cellpadding=\"0\" cellspacing=\"0\" width=\"95%\">
    <tr>
      <td width=\"100%\" class=\"row1\">נכתב על ידי: $author בתאריך: $time<br></td>
    </tr>
   <tr>
      <td width=\"100%\">
$content
</td>
    </tr>
  </table>
  </center>
</div>
<br><br><hr>"
;
comments(); //// פונקציה שלי.. לא להתייחס
echo "
<br><br><br>
<center><a href=\"javascript:history.go(-1)\">חזור דף<a></center>
</div></div>"



אם מישהו מבין מה הבעיה בבקשה תעזרו לי..

תודה

-roee- 13-05-06 19:18

someone plz?


כל הזמנים הם GMT +2. הזמן כעת הוא 11:54.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ