Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a textfile which contain words like that:
Yigit Ozkavci 19
Efe Ozkavci 18
Yeni Bar 35
.
.
.
They are exist in database and also in textfile, what I want to do is to read those datas and get them in seperate variables, I know how to read a file line by line, but with a foreach loop can I echo them seperately and send data to another php file ?
Why not just make use of file() ? It reads entire content inside an array.
<?php
$arr = file('yourfile.txt');
You can access Yigit Ozkavci 19 by echo $arr[0]; and others so on...
If you want to process it... you can just run it on foreach like this
foreach($arr as $val)
{
echo strtoupper($val); // Just a demonstration ..
}
<?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.example.com/');
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . $line . "<br />\n";
}
?>
Hope This Helps :)
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm new in File handling. So I was wondering how would I go about to write a php file with php?
Let's say I want to make a php script which creates a file which contains the following code:
PHP File TO be Created
<?php
$item = "takes a variable from current file and put it here";
?>
Let's say I have a php which took the following from my form:
Code which takes a variable and writes it to another php file, exactly as it is
<?php
$item = $_GET['shirts'];
//Code which writes to Php File above
?>
I have no idea how to do this. Please be very explicit when you explain.
Thanks :)
Like this:
$var='that';
file_put_contents('newfile.php','<?php echo "thisthat' . $var . '"; ?>');
Note that if $var is coming from user input in any way you will need to be extremely careful to sanitize it so a hacker can't just do anything he wants on your server.
Documentation for file_put_contents here: php.net/file_put_contents
file_put_contents('fileToCreate.php', '<?php' . "\n" . '$item = "' . $item . '";' . "\n" . '?>')
viz here: php.net/file_put_contents
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have an SMF website and i'm actually trying to get some header information which includes the title of a particular thread, the url but i've been finding it difficult to get the unique link affixed to the url using PHP.
Here's the url: http://example.com/index.php?topic=6449.msg6858
I'm actually looking for a way to extract the number 6449, I've tried to use the php GET function but it doesn't work.
$parts = explode('.', $_GET['topic']);
echo $parts[0];
// PHP 5.4+
echo explode('.', $_GET['topic'])[0];
See it in action
This would work, too
echo (int) $_GET['topic'];
See it in action
You want to use a combination of substr and strpos (to find the first occurence of a period)
$number = substr($_GET['topic'], 0, strpos($_GET['topic'], '.'));
// 6449
$arr = array();
if (preg_match("/([\\d]+)([.]{1}msg[\\d]+)/", $_GET["topic"], $arr) == 1) {
echo $arr[1];
} else {
trigger_error("not found", E_USER_ERROR);
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a text file on my local server. I want to read content data of this text file and write it into textbox in a html .
Could you please help me?
$data = file_get_contents('yourfile.txt');
echo '<textarea>', htmlspecialchars($data), '</textarea>';
The file_get_contents() loads the data, and then you just need to echo it. Using htmlspecialchars() takes care of escaping any of the data, as needed in the context of HTML.
$textAreaContent = "";
$fp = fopen("read_file.txt", "r");
// If file exist and opened
if($fp)
{
while (($buffer = fgets($fp, 1024)) !== false)
$testAreaContent .= $buffer;
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to create an CMS-system where I can add photos to my website, and for the photo-part, I want to have the ability to enter which programs I had used to create that photo.
I should be possible to add more than one program.
Right now I am saving the programs in the database like this:
In the programs-row:
photoshop illistrator indesign
Then at my website, it could be nice if the icons/logos of the used programs, could show up next to the photo.
So my question is how to do create a new div, what a new class, based on the words from the programs-row?
Fx:
photoshop illustrator indesign
Becomes to:
<div class="photoshop"></div>
<div class="illustrator"></div>
<div class="indesign"></div>
Hope you guys can help me with this problem :)
Thanks ;)
Use the explode function and a foreach loop to perform the string manipulation.
$programs = explode(" ", $data);
foreach($programs as $value) {
//Echo out the html - $value contains the program name
}
I leave it to you to figure out how to format the program name with the HTML that you need.
$fx = "photoshop illistrator indesign";
$words = explode(" ", $fx);
array_walk($words, function(&$n) {
echo '<div class="'.$n.'"></div>';
});
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I was wondering if there was a way to bold certain words on a line. For example if I wanted every third word on a line bold, how would I do it. I am currently using addText but that requires the whole line to be bold or not bold. Any responses would be greatly appreciated.
You will need to use createTextRun() method. I have tried with Text.php file from Examples folder, and here is code relevant for your problem:
$textrun = $section->createTextRun();
$sentence='I am sentence, and every third word will be bold. This is bold.';
$word_arr=explode(' ', $sentence);
$styleFont = array('bold'=>true, 'size'=>16, 'name'=>'Calibri');
$styleFont2 = array('bold'=>false, 'size'=>16, 'name'=>'Calibri');
$c = 0;
for($i = 0; $i < count($word_arr); $i++)
{
$c++;
if($c % 3 == 0)
{
$textrun->addText($word_arr[$i].' ', $styleFont);
}
else
{
$textrun->addText($word_arr[$i].' ', $styleFont2);
}
}
You could tweak it to get what you want, but, basically, by using of mentioned method, it is possible to get different styles in same line.