How to write a Loop for a Dummy? [closed] - php

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
this is probably an easy question, but I am not really a coder. I maintain a website for a group I belong to, and there are some php forms. I am trying to enhance a form, and I have added this php code, which works (see below). My question is, how can I put this code into a loop so that it repeats 10 times, for "01", "02", etc., "10" strings (code below is for "01" of the series)? Thanks for any help.
//Clean up the Photo Title & Maker Name to remove non-standard chars and replace spaces with underscores and generate a suggested fliename
$photo_01_clean = str_replace(" ","75357",$photo_01_name);
$photo_01_clean1 = str_replace("#","at",$photo_01_clean);
$photo_01_clean2 = preg_replace('/[^a-z0-9]/i', '', $photo_01_clean1);
$photo_01_clean3 = str_replace("75357","_",$photo_01_clean2);
$photo_01_maker_clean = str_replace(" ","75357",$photo_01_maker_name);
$photo_01_maker_clean1 = str_replace("#","at",$photo_01_maker_clean);
$photo_01_maker_clean2 = preg_replace('/[^a-z0-9]/i', '', $photo_01_maker_clean1);
$photo_01_maker_clean3 = str_replace("75357","_",$photo_01_maker_clean2);
$photo_01_filename_gen = $club_code."-01-".$photo_01_clean3."-".$photo_01_maker_clean3.".jpg";

You'd require a for loop control structure. You can find tons of resources that would teach you how to do it. example

Var i;
For (i =1; i<11; i++)
Execute Code here.

Related

Extract a part of variable ending with dash "-" [closed]

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 variable $TYPE=K180M-2
I need to "extract only the part until the dash (K180M) in a new variable.
How can I do it?
You may try:
$arr=explode("-", $TYPE);
$arr[0] will give you the desired result.
<?php
$newType = substr($TYPE, 0, stripos($TYPE, '-'));
?>
Will work.
You can use explode :
<?php
$K180M = '45';
$TYPE = 'K180M-2';
$var = explode('-',$TYPE,2);
$$var[0]; // this is your new variable named $K180M
var_dump($$var[0]); // result 45
If you prefer a regular expression, use preg_replace()
// Delete the dash and anything following it:
$type_without_dash = preg_replace("/-.*/", "", $TYPE);
Simply use
$value=strstr($TYPE,'-',TRUE);

preg match for known value plus 7 charecters [closed]

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
Can anyone help me get the value of IFC/USD 0.00001031 from the webpage http://infinitecoin.com.
I need to grab the value after IFC/USD..
The way I thought to do it was to:
$file_string = file_get_contents('http://infinitecoin.com');
preg_match('/IFC/USD plus next 11 charecters', $file_string, $title);
$value = $title[1];
echo $title_out ;
But im not sure how to ask PHP to find IFC/USD then return the next 11 characters after that.
If I could accomplish this, my task would be solved..
Any help would be great.
Thank you
Jason
$output = array();
preg_match("/(?<=IFC\/USD\s)[\d\.]+/", 'IFC/USD 0.00001015', $output);
$output will look like this:
Array
(
[0] => 0.00001015
)

Remove specific match from a string [closed]

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 want to remove a particular match of characters from a string.
For example i have strings;
topics-p10-new-model-cars
topics-p20-new-model-cars
topics-p30-new-model-cars
topics-p40-new-model-cars
Then i need the results as,
topics-new-model-cars
topics-new-model-cars
topics-new-model-cars
topics-new-model-cars
That means i want to remove p10-,p20-,etc..
.Those are the page numbers. It may be any number..
How can i do this..? Thanks in advance
Try this:
$result = preg_replace('/\-p\d+/', '', $string);
Note: I'm assuming that the string format does not change (I mean this [topics-p10-new-model-cars]). If my assumption is right.
Then you can do this
if (textBox1.Text.Contains("-p10-"))
{
//topics-p10-new-model-cars
String[] splited = textBox1.Text.Split(new char[] {'-'});
String rString = String.Format("{0}-{1}-{2}-{3}",
splited[0],splited[2],splited[3],splited[4]);
MessageBox.Show(rString);
}
//OR This method
if (textBox1.Text.Contains("-p10-"))
{
String result = textBox1.Text.Replace("p10-", "");
MessageBox.Show(result);
}
With 'preg-replace'::
For, example:
<?
echo preg_replace('/p[0-9]+\-/', '', 'topics-p10-new-model-cars');
?>
Follow this link:
http://www.php.net/manual/en/function.preg-replace.php

Make every word in a string into classes [closed]

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>';
});

PHPWord bold certain words on a line [closed]

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.

Categories