Skip to content

Commit 6b3cb1b

Browse files
done
1 parent cb8ed61 commit 6b3cb1b

9 files changed

Lines changed: 308 additions & 0 deletions

File tree

Even_Odd.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Program: Even or Odd
4+
* Description: Checks if a given number is even or odd.
5+
*/
6+
7+
$number = 15; // You can change this value
8+
9+
echo "<h2>Even or Odd Checker</h2>";
10+
echo "Number: " . $number . "<br>";
11+
12+
if ($number % 2 == 0) {
13+
echo "<p style='color: #238636; font-weight: bold;'>$number is an EVEN number.</p>";
14+
} else {
15+
echo "<p style='color: #da3633; font-weight: bold;'>$number is an ODD number.</p>";
16+
}
17+
18+
// Additional demonstration with a loop
19+
echo "<h3>Checking numbers from 1 to 5:</h3>";
20+
for ($i = 1; $i <= 5; $i++) {
21+
$status = ($i % 2 == 0) ? "Even" : "Odd";
22+
echo "Number $i is $status<br>";
23+
}
24+
?>

Factorial.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Program: Factorial Calculation
4+
* Description: Calculates the factorial of a number using a for loop.
5+
*/
6+
7+
$num = 5;
8+
$factorial = 1;
9+
10+
echo "<h2>Factorial Calculator</h2>";
11+
12+
if ($num < 0) {
13+
echo "Factorial is not defined for negative numbers.";
14+
} else {
15+
for ($i = 1; $i <= $num; $i++) {
16+
$factorial = $factorial * $i;
17+
}
18+
echo "The factorial of <strong>$num</strong> is: <strong>$factorial</strong>";
19+
}
20+
21+
echo "<hr>";
22+
echo "<h3>Formula:</h3>";
23+
echo "n! = n × (n-1) × (n-2) × ... × 1";
24+
?>

Fibonacci.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Program: Fibonacci Series
4+
* Description: Generates the Fibonacci sequence up to a specified number of terms.
5+
*/
6+
7+
$n = 10; // Number of terms
8+
$first = 0;
9+
$second = 1;
10+
11+
echo "<h2>Fibonacci Series</h2>";
12+
echo "Generating $n terms:<br><br>";
13+
14+
echo "<div style='font-family: monospace; font-size: 1.2rem; background: #f4f4f4; padding: 10px; border-radius: 5px; color: #333;'>";
15+
16+
for ($i = 0; $i < $n; $i++) {
17+
if ($i <= 1) {
18+
$next = $i;
19+
} else {
20+
$next = $first + $second;
21+
$first = $second;
22+
$second = $next;
23+
}
24+
25+
echo $next;
26+
if ($i < $n - 1) {
27+
echo ", ";
28+
}
29+
}
30+
31+
echo "</div>";
32+
33+
echo "<p>The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones.</p>";
34+
?>

For_Loop_Table.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Program: Multiplication Table using For Loop
4+
* Description: Generates a multiplication table for a given number.
5+
*/
6+
7+
$num = 7;
8+
9+
echo "<h2>Multiplication Table of $num</h2>";
10+
echo "<table border='1' cellpadding='10' style='border-collapse: collapse; width: 200px; text-align: center; border: 1px solid #30363d;'>";
11+
echo "<tr style='background: #1f242c; color: #58a6ff;'><th>Expression</th><th>Result</th></tr>";
12+
13+
for ($i = 1; $i <= 10; $i++) {
14+
$res = $num * $i;
15+
$bg = ($i % 2 == 0) ? "#161b22" : "#0d1117";
16+
echo "<tr style='background: $bg;'><td>$num x $i</td><td>$res</td></tr>";
17+
}
18+
19+
echo "</table>";
20+
?>

Prime_Number.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Program: Prime Number Checker
4+
* Description: Checks whether a given number is prime or not.
5+
*/
6+
7+
$number = 17;
8+
$isPrime = true;
9+
10+
echo "<h2>Prime Number Checker</h2>";
11+
echo "Number to check: <strong>$number</strong><br><br>";
12+
13+
if ($number <= 1) {
14+
$isPrime = false;
15+
} else {
16+
for ($i = 2; $i <= sqrt($number); $i++) {
17+
if ($number % $i == 0) {
18+
$isPrime = false;
19+
break;
20+
}
21+
}
22+
}
23+
24+
if ($isPrime) {
25+
echo "<span style='padding: 5px 10px; background: #238636; color: white; border-radius: 4px;'>$number is a PRIME number</span>";
26+
} else {
27+
echo "<span style='padding: 5px 10px; background: #da3633; color: white; border-radius: 4px;'>$number is NOT a prime number</span>";
28+
}
29+
30+
echo "<br><br><em>Definition: A prime number is a natural number greater than 1 that is not a product of two smaller natural numbers.</em>";
31+
?>

Switch_Case.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Program: Switch Case Demonstration
4+
* Description: Uses a switch statement to display the day of the week.
5+
*/
6+
7+
$day = date("w"); // Get current day of the week (0 for Sunday, 6 for Saturday)
8+
9+
echo "<h2>Switch Case: Day of the Week</h2>";
10+
echo "Today is: ";
11+
12+
switch ($day) {
13+
case 0:
14+
echo "<strong>Sunday</strong> - Time to relax!";
15+
break;
16+
case 1:
17+
echo "<strong>Monday</strong> - Back to work/college.";
18+
break;
19+
case 2:
20+
echo "<strong>Tuesday</strong> - Keeping the momentum.";
21+
break;
22+
case 3:
23+
echo "<strong>Wednesday</strong> - Hump day!";
24+
break;
25+
case 4:
26+
echo "<strong>Thursday</strong> - Almost there.";
27+
break;
28+
case 5:
29+
echo "<strong>Friday</strong> - Weekend is coming!";
30+
break;
31+
case 6:
32+
echo "<strong>Saturday</strong> - Enjoy your weekend!";
33+
break;
34+
default:
35+
echo "Invalid day!";
36+
}
37+
38+
echo "<br><br>Note: This program uses the server's current date to determine the day.";
39+
?>

index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ <h3>Explorer</h3>
6060
<ion-icon name="refresh-outline"></ion-icon>
6161
</button>
6262
</div>
63+
<!-- Search Bar -->
64+
<div class="search-container">
65+
<ion-icon name="search-outline"></ion-icon>
66+
<input type="text" id="file-search" placeholder="Search programs...">
67+
</div>
6368
<ul id="file-list" class="file-list">
6469
<!-- Files will be injected here -->
6570
<div class="loading-spinner">
@@ -91,6 +96,9 @@ <h3>Explorer</h3>
9196
<span id="current-filename">Select a file to view</span>
9297
</div>
9398
<div class="actions">
99+
<button id="copy-btn" class="icon-btn" title="Copy Code" disabled style="margin-right: 5px;">
100+
<ion-icon name="copy-outline"></ion-icon>
101+
</button>
94102
<button id="run-btn" class="btn btn-primary" disabled>
95103
<ion-icon name="play"></ion-icon> Run Code
96104
</button>

script.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const runBtn = document.getElementById('run-btn');
1010
const outputConsole = document.getElementById('output-console');
1111
const clearConsoleBtn = document.getElementById('clear-console');
1212
const refreshFilesBtn = document.getElementById('refresh-files');
13+
const fileSearchInput = document.getElementById('file-search');
14+
const copyBtn = document.getElementById('copy-btn');
1315

1416
const CACHE_KEY = 'php_repos_cache_v1';
1517
const CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
@@ -30,6 +32,19 @@ document.addEventListener('DOMContentLoaded', () => {
3032
fetchFiles();
3133
});
3234
}
35+
36+
// Search functionality
37+
if (fileSearchInput) {
38+
fileSearchInput.addEventListener('input', (e) => {
39+
const searchTerm = e.target.value.toLowerCase();
40+
filterFiles(searchTerm);
41+
});
42+
}
43+
44+
// Copy functionality
45+
if (copyBtn) {
46+
copyBtn.addEventListener('click', copyToClipboard);
47+
}
3348
});
3449

3550
// Fetch files from GitHub
@@ -84,10 +99,16 @@ async function fetchFiles(isBackground = false) {
8499
"Constants.php",
85100
"Data_Type.php",
86101
"Dot_Operator.php",
102+
"Even_Odd.php",
103+
"Factorial.php",
104+
"Fibonacci.php",
105+
"For_Loop_Table.php",
87106
"HelloWorld.php",
88107
"Increment-&-Decrement-Operators.php",
89108
"Operator.php",
109+
"Prime_Number.php",
90110
"String.php",
111+
"Switch_Case.php",
91112
"array.php",
92113
"bitwise.php",
93114
"calculate_truth_table.php",
@@ -133,6 +154,19 @@ async function fetchFiles(isBackground = false) {
133154
});
134155
}
135156

157+
// Filter files based on search term
158+
function filterFiles(term) {
159+
const items = fileListEl.querySelectorAll('.file-item');
160+
items.forEach(item => {
161+
const fileName = item.innerText.toLowerCase();
162+
if (fileName.includes(term)) {
163+
item.style.display = 'flex';
164+
} else {
165+
item.style.display = 'none';
166+
}
167+
});
168+
}
169+
136170
// Poll for updates every 5 minutes (reduced from 60s to save API calls)
137171
setInterval(() => fetchFiles(true), 300000);
138172

@@ -168,13 +202,47 @@ async function loadFile(file, element) {
168202

169203
runBtn.disabled = false;
170204
runBtn.innerHTML = '<ion-icon name="play"></ion-icon> Run Code';
205+
206+
if (copyBtn) copyBtn.disabled = false;
171207

172208
// Log to terminal
173209
renderOutput(`Loaded file: ${file.name}\nReady to execute...`, true);
174210

175211
} catch (error) {
176212
codeDisplayEl.innerHTML = `// Error loading file: ${error.message}`;
177213
runBtn.innerHTML = '<ion-icon name="alert-circle"></ion-icon> Error';
214+
if (copyBtn) copyBtn.disabled = true;
215+
}
216+
}
217+
218+
// Copy Code to Clipboard
219+
async function copyToClipboard() {
220+
if (!currentCode) return;
221+
222+
try {
223+
await navigator.clipboard.writeText(currentCode);
224+
225+
// Show success tooltip
226+
const tooltip = document.createElement('div');
227+
tooltip.className = 'copy-tooltip';
228+
tooltip.innerText = 'Copied!';
229+
copyBtn.parentElement.appendChild(tooltip);
230+
231+
setTimeout(() => tooltip.classList.add('show'), 10);
232+
setTimeout(() => {
233+
tooltip.classList.remove('show');
234+
setTimeout(() => tooltip.remove(), 300);
235+
}, 2000);
236+
237+
// Change icon temporarily
238+
const originalIcon = copyBtn.querySelector('ion-icon').name;
239+
copyBtn.querySelector('ion-icon').name = 'checkmark-outline';
240+
setTimeout(() => {
241+
copyBtn.querySelector('ion-icon').name = originalIcon;
242+
}, 2000);
243+
244+
} catch (err) {
245+
console.error('Failed to copy: ', err);
178246
}
179247
}
180248

style.css

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,40 @@ body {
117117
padding: 15px 0;
118118
}
119119

120+
/* Search Bar */
121+
.search-container {
122+
padding: 5px 15px 15px;
123+
position: relative;
124+
display: flex;
125+
align-items: center;
126+
}
127+
128+
.search-container ion-icon {
129+
position: absolute;
130+
left: 28px;
131+
color: var(--text-muted);
132+
font-size: 0.9rem;
133+
}
134+
135+
#file-search {
136+
width: 100%;
137+
background: rgba(255, 255, 255, 0.05);
138+
border: 1px solid var(--glass-border);
139+
border-radius: 8px;
140+
padding: 8px 12px 8px 35px;
141+
color: var(--text-main);
142+
font-family: var(--font-heading);
143+
font-size: 0.85rem;
144+
outline: none;
145+
transition: all 0.2s;
146+
}
147+
148+
#file-search:focus {
149+
background: rgba(255, 255, 255, 0.08);
150+
border-color: var(--primary);
151+
box-shadow: 0 0 0 2px var(--primary-glow);
152+
}
153+
120154
.file-list-container h3 {
121155
padding: 10px 25px;
122156
font-size: 0.7rem;
@@ -487,6 +521,32 @@ pre[class*="language-"] {
487521
color: var(--text-main);
488522
}
489523

524+
.icon-btn:disabled {
525+
opacity: 0.3;
526+
cursor: not-allowed;
527+
}
528+
529+
/* Tooltip for copy button */
530+
.copy-tooltip {
531+
position: absolute;
532+
top: -35px;
533+
right: 0;
534+
background: var(--success);
535+
color: white;
536+
padding: 4px 8px;
537+
border-radius: 4px;
538+
font-size: 0.75rem;
539+
pointer-events: none;
540+
opacity: 0;
541+
transform: translateY(10px);
542+
transition: all 0.3s;
543+
}
544+
545+
.copy-tooltip.show {
546+
opacity: 1;
547+
transform: translateY(0);
548+
}
549+
490550
/* Loading Spinner */
491551
.loading-spinner {
492552
display: flex;

0 commit comments

Comments
 (0)